Displaying 121-130 of 274 results.
Resolved: PHP get the first word of a sentence string
posted by admin on May 22, 2016
I want to extract the first word of a variable from a string. For example, take this input:

<?php $myvalue = 'Test me more'; ?>

The resultant output should be Test, which is the first word of the input. How can I do this?Read more
Resolved: Yii redirect from model
posted by admin on May 22, 2016
In model I try use redirect, but it is not working


It working only from controller. I want to redirect from modelRead more
Resolved: Yii get renderpartial and store in value
posted by admin on May 22, 2016
I want to store renderpartial, and dont want to echo

<?php $this->renderPartial($view, $data); ?>

It echo content automatically.
I want to store it like

$value = "my value";
$value .= $this->renderPartial($view, $data);
Read more
Wiki: Yii 1.1: How to work with flash messageswiki
posted by admin on May 22, 2016
Set your messages in a controller:

Yii::app()->user->setFlash('success', "Data1 saved!");
Yii::app()->user->setFlash('error', "Data2 failed!");
Yii::app()->user->setFlash('notice', "Data3 ignored.");

Display them in your view:

foreach(Yii::app()->user->getFlashes() as $key => $message) {
echo '<div class="flash-' . $key . '">' . $message . "</div>\n";

Setting flash messages
A flash message is used in order to keep a message in session through one or several requests of the same user. By default, it is removed from session after it has been displayed to the user. Flash messages are usually used in combination with HTTP redirections, because in this case there is no view, so messages can only be displayed in the request that follows redirection.

A flash message has a name and a content (AKA key and value). It is an entry of an associative array. The name is a string: often "notice", "success", or "error", but it can be anything. The content is usually a string. You can put HTML tags in your message if you display it raw. You can also set the message value to a number or an array: it will be serialized and kept in session like a string.

Flash messages can be set using the setFlash() Method of CWebUser. For example, if you would like to inform the user that his changes were successfully saved, you could add the following line to your Controller:

Yii::app()->user->setFlash('success', "Data saved!");
$this->redirect(array('thing/view', 'id' => 1));

In this example we used the key 'success'. If you want to define more than one flash messages, you will have to use different keys.
Displaying flash messages
To check for flash messages we use the hasFlash() Method and to obtain the flash message we use the getFlash() Method. Since Yii v1.1.3, there is also a method getFlashes() to fetch all the messages.

By default, fetching a message deletes it from the session. This means that a message is meant to be displayed only on the first page served to the user. The fetching methods have a boolean parameter that can change this behavior. See the API links in the previous paragraph.

Displaying statically
So showing of the flash message defined above in a view is done by

<?php if(Yii::app()->user->hasFlash('success')):?>
<div class="info">
<?php echo Yii::app()->user->getFlash('success'); ?>
<?php endif; ?>

These few lines of code will make a flash message with the key "success" visible to the user within a div of class "info". The message will be displayed until this or another page is (re)loaded in the browser.

If you want to always display all the flash messages, then you should add a block to your layout (by default protected/views/layout/main.php). Here is a more elaborate example:

$flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
echo '<ul class="flashes">';
foreach($flashMessages as $key => $message) {
echo '<li><div class="flash-' . $key . '">' . $message . "</div></li>\n";
echo '</ul>';

The default CSS created by the Yii script yiic webapp has directives for three classes of flash messages on a div tag: flash-error, flash-notice, flash-success.

The best way to know if some flash messages are set is to check if Yii::app()->user->getFlashes() is empty. Since v1.1.7, Yii keeps an associative array of the flash keys in the form array("key1" => 0, ...), or null if not flash message is set. You can fetch this with Yii::app()->user->getState(CWebUser::FLASH_COUNTERS) but this is not recommended, as Yii could change this internal process.

Displaying dynamically (with Javascript)
If you want the flash message to appear somewhere above the content and then automatically fade out after a few seconds, you will have to add the following lines to your view:

'$(".info").animate({opacity: 1.0}, 3000).fadeOut("slow");',

With these lines of code we register a piece of jQuery (already included with YII) javascript code, using 'myHideEffect' as ID. It will be inserted in the jQuery's ready function (CClientScript::POS_READY). Due to the chainablity of jQuery the little script will run two effects on the .info DIV sequentially:

.animate({opacity: 1.0}, 3000)

Normally this would animate the .info DIV to a full opacity within 3 seconds. But the DIV is already rendered with full opacity upon page load, so calling this effect will just cause a delay for 3 seconds.


This is the fadeOut effect which will hide the .info DIV at slow speed.Read more
Wiki: PHP strtotime() Functionwiki
posted by admin on May 22, 2016
Parse English textual datetimes into Unix timestamps:

echo(strtotime("now") . "
echo(strtotime("3 October 2005") . "
echo(strtotime("+5 hours") . "
echo(strtotime("+1 week") . "
echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "
echo(strtotime("next Monday") . "
echo(strtotime("last Sunday"));

Definition and Usage
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

Note: Be aware of dates in the m/d/y or d-m-y formats; if the separator is a slash (/), then the American m/d/y is assumed. If the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential errors, you should YYYY-MM-DD dates or date_create_from_format() when possible.



Parameter Description
time Required. Specifies a date/time string
now Optional. Specifies the timestamp used as a base for the calculation of relative dates

Technical Details
Return Value: Returns a timestamp on success. FALSE on failure
PHP Version: 4+
Changelog: PHP 5.3.0: Now relative time formats such as this week, previous week, last week, and next week interprets a week period of Monday through Sunday, rather then a 7-day period relative to the current date/time
PHP 5.3.0: Now 24:00 is a valid format
PHP 5.2.7: In earlier versions, if requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month it would incorrectly add one week to the returned timestamp. This has been corrected now
PHP 5.1.0: Returns FALSE on failure (earlier versions returns -1), and issues E_STRICT and E_NOTICE time zone errors
PHP 5.0.2: Now correctly computes "now" and other relative times from current time, not from today's midnight
PHP 5.0.0: Allows microseconds (but they are ignored)Read more
Resolved: HTML CSS youtube vimeo video width 100 perccent
posted by admin on May 22, 2016
I want to stretch my youtube and vimeo video embed or iframe.Read more
Resolved: PHP compose class property by string and value
posted by admin on May 22, 2016
I have object or class.

class Class1{
public $language = "English";
public $languageru = "Russian";

public function composeValue(){
//return my value, or empty or "ru"

$class = new Class1();
$value = $class->composeValue();
// I want something like this
echo $class->language.$value
//But it is not working
Read more
Resolved: CSS html textarea with 100 % percent right part goes beyond the scope of the block
posted by admin on May 22, 2016



with: 100%;
width: 500px;

Textarea bigger than div. How to resolve it?Read more
Resolved: Select last row in MySQL
posted by admin on May 21, 2016
How can I SELECT the last row in a MySQL table?Read more
Resolved: MySQL - Count Number of Unique Values
posted by admin on May 21, 2016
If I have three columns:

orderNumber, name, email

and I would like to count how many unique emails are in the table how would I go about doing so?

A statement like:

SELECT count(email) FROM orders

gives me the total count.
I tried

SELECT DISTINCT count(email) FROM orders

but that does not seem to be giving me the numbers I am expecting.Read more