I was astounded to see web pages using large-size-auto-playing-video at their landing page. They are awesome aside from draw backs (it consumes large amount of bandwidth) they are cool and they convey message well . So I thought what if error messages would like fun too like their landing page or their about page , what if 404 messages would be videos
A blog for PHP, YII Framework,Javascript , MySQL, Linux related stuff
Tuesday, August 12, 2014
The future of 404 pages
I was astounded to see web pages using large-size-auto-playing-video at their landing page. They are awesome aside from draw backs (it consumes large amount of bandwidth) they are cool and they convey message well . So I thought what if error messages would like fun too like their landing page or their about page , what if 404 messages would be videos
How to read long BLOG
The secret to reading a long blog is to remove distractions. Distractions like ads , moving images or auto played videos are the best elements to keep out of focus in reading long post.
The solution
ZOOM In the PAGE.
Zoom in until all you can see are the text that you want to read . Then you can now start reading the long post part by part .Yii - Problem with Date Comparison
Do you ever encounter this problem
where you feel your code is right and should work yet still you got nothing
Try using the quote string on your comparison
for example
$criteria->addCondition("date(date_created) = \"$yourDate\"");
Like that..
hope you find this helpful
Saturday, August 9, 2014
Yii - Calling Widget - PHPStorm Friendly
Old WAY
When I was just starting out. These code looks hideously cryptic and hard to understand .
<?php $this->widget('zii.widgets.grid.CGridView', array(
/*'type'=>'striped bordered condensed',*/
'itemsCssClass'=>'table table-striped',
'dataProvider'=>$gridDataProvider,
'template'=>"{items}",
'columns'=>array(
array('name'=>'id', 'header'=>'#'),
array('name'=>'firstName', 'header'=>'First name'),
array('name'=>'lastName', 'header'=>'Last name'),
array('name'=>'language', 'header'=>'Language', 'type'=>'raw'),
array('name'=>'usage', 'header'=>'Usage', 'type'=>'raw'),
),
)); ?>
so I went experimenting on how to make these more readable and here is what I have found.
$myGridview = new CGridView();
$myGridview->itemsCssClass = 'table table-hover';
$myGridview->dataProvider = $gridDataProvider;
$myGridview->template = "{items}";
$myGridview->columns = array(
array('name'=>'id', 'header'=>'#'),
array('name'=>'firstName', 'header'=>'First name'),
array('name'=>'lastName', 'header'=>'Last name'),
array('name'=>'language', 'header'=>'Language', 'type'=>'raw'),
array('name'=>'usage', 'header'=>'Usage', 'type'=>'raw'),
);
$myGridview->init();
echo $myGridview->run(); // to print the widget
yes the code looks longer than the first one , If you are using php storm as your IDE you can easily explore your widget's other attributes and functions.
Thursday, August 7, 2014
How to implement REST using Yii
DONT YOU DARE LEAVE YII!
Don't jump in their wagon yet. Stay on the boat. Here is how to create REST API using Yii
I will be using yii version 1.15
its easy actually just paste these
array('api/list', 'pattern'=>'api/<model:\w+>', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/update', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'PUT'),
array('api/delete', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'DELETE'),
in your main.php
here is my complete configuration
'rules'=>array(
array('api/list', 'pattern'=>'api/<model:\w+>', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/update', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'PUT'),
array('api/delete', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'DELETE'),
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
Now that you pasted that code. Create a ApiController.php file on your controllers folder.
heres the complete code of that file
here an example code from my ApiController
public function actionView()
{
// header('Content-Type: application/json');
/*retrieve json string with contact id */
if (class_exists($_GET['model'])) {
$foundContact = new $_GET['model'];
$criteria = new CDbCriteria;
$criteria->compare("rec_id",$_GET['id']);
$foundContact = $foundContact::model()->find($criteria);
echo CJSON::encode($foundContact);
}else{
throw new CHttpException(404,"Sorry we cant find that contact");
}
/*return the full data*/
}
Don't jump in their wagon yet. Stay on the boat. Here is how to create REST API using Yii
I will be using yii version 1.15
its easy actually just paste these
array('api/list', 'pattern'=>'api/<model:\w+>', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/update', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'PUT'),
array('api/delete', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'DELETE'),
in your main.php
here is my complete configuration
'rules'=>array(
array('api/list', 'pattern'=>'api/<model:\w+>', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/update', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'PUT'),
array('api/delete', 'pattern'=>'api/<model:\w+>/<id:\d+>', 'verb'=>'DELETE'),
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
Now that you pasted that code. Create a ApiController.php file on your controllers folder.
heres the complete code of that file
class ApiController extends Controller { // Members /** * Key which has to be in HTTP USERNAME and PASSWORD headers */ Const APPLICATION_ID = 'ASCCPE'; /** * Default response format * either 'json' or 'xml' */ private $format = 'json'; /** * @return array action filters */ public function filters() { return array(); } // Actions public function actionList() { } public function actionView() { } public function actionCreate() { } public function actionUpdate() { } public function actionDelete() { } }And you are DONE!..
here an example code from my ApiController
public function actionView()
{
// header('Content-Type: application/json');
/*retrieve json string with contact id */
if (class_exists($_GET['model'])) {
$foundContact = new $_GET['model'];
$criteria = new CDbCriteria;
$criteria->compare("rec_id",$_GET['id']);
$foundContact = $foundContact::model()->find($criteria);
echo CJSON::encode($foundContact);
}else{
throw new CHttpException(404,"Sorry we cant find that contact");
}
/*return the full data*/
}
Wednesday, August 6, 2014
Angular JS weird error
So I encountered these error today and only to find out the solution is just to include
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
then inject that module in your module like these
var app = angular.module('myapp', ['ngRoute']);
et viola ! error message gone!
Tuesday, August 5, 2014
PHP - exec() vs system() vs passthru()
I've learned from experience.
Similarities : They are all used to execute system commands
shell_exec()
- I will execute your command and return the full string of the result.exec()
- "shell_exec" stop copying my feature... *works the same as shell_execsystem()
- I will run your command but I will only return the last line . Please use me if you only want a one liner outputpassthru()
- I will run your command and proceed immediately with the next line of code. The output will be sent to output buffer dont worry about me.
Subscribe to:
Posts (Atom)