Monday, February 22nd, 2010
I’ve been coding away all week, that is between my other jobs at home
In all my ‘wisdom’ and persistence i made a small app with Yii which stores data in an array and serializes it into a db, and a basic CRUD, a proof of concept to see if the framework was capable of doing this and in the fastest way possible.
No problem so far, getting it is simple, but apparently you Yii doesn’t permit everything. So you need a $temp variable to store the model data in, suffice to say that it isn’t really the shortest route to take nor in my opinion the fastest bus alas I have to do with it. This little app of not more then a 60 lines of code took me four days, four damn days to figure out the error, honestly if we have methods to ‘save space’ in your coding why not permit them?
I’m not going to bother everybody with my nagging so, I’ll stop here.
For those who want to see the topic on the yii forums.
Posted in General, Projects, tutorials | No Comments »
Sunday, December 20th, 2009
I’m toying with the Yii Framework for some time now and even if i cost me a lot of anger and frustration in the beginning I’m starting to like it more and more, alas I do have to say that the documentation isn’t always that clear and for someone who begins or who’ll write some large applications the configuration file can be a hassle so here’s my solution:
Brake down the configuration file in multiple files, this will give you some speed disadvantage and some will saying that I’m raping Yii framework purpose for speed but at least to me it seems more clear
This is the protected.config/main.php
dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'WEBSITENAME',
'modules'=>array(
'users'=>array(
//sub modules in the module users
'modules'=>array(
'messaging',
'profile',
'dashboard',
)
),
'about',
'forums',
),
// preloading 'log' component active loading
'preload'=>array('log'),
// autoloading model and component classes lazy loading
// I make the difference between CformModel and CActiveRecord
'import'=>array(
'application.models.*',
'application.models.forms.*',
'application.models.database.*',
),
// application components
'components'=>array(
// enable cookie-based authentication
'user'=>array('allowAutoLogin'=>true),
// data relinquished to database.php
// for easy access and usability as also for the future
// installation procedure, it's less to write to a file
'db'=>include(dirname(__FILE__).'/database.php'),
// for a better overview we exculded url routes to a seperate file
'urlManager'=>include(dirname(__FILE__).'/routes.php'),
//authentication component needs data from db for CdbConnection
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
'defaultRoles'=>array('authenticated', 'guest'),
),
//security measures
'request'=>array(
'enableCsrfValidation'=>true,
'enableCookieValidation'=>true,
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
// uncomment the following if you want static params in the application
//'params'=>array(include(dirname(__FILE__).'/params.php'))
);
database.php
'CDbConnection',
'connectionString'=>'mysql:host=localhost;dbname=mysql',
//'connectionString'=>'pgsql:host=localhost;port=5432;dbname=mysql',
'username' => 'root',
'password' => '',
);
?>
routes.php
'path', // path or get
'urlSuffix' => '', //.html .whateverextentionyouwant
'showScriptName' => true,
'rules'=>array(
'users/recovery/perimeterSecurity/'=>'users/recovery/perimeterSecurity',
),
);
?>
param.php
//nothing in it at the moment
Posted in tutorials | 2 Comments »
Monday, September 7th, 2009
Yii framework (yiiframework.com) is a very fast php5 framework. At first it seems like a jungle in the code, everything is put into motion to make the framework very fast. It’s been really a steep lurning curve, even if you seen oop programming, alas seen it in a totally different way that corresponds to nothing in yii. So you have to adapt to it’s style of coding, writing and thinking.
It’s not a regular MVC framework, yii had a module concept integrated, if you want to use it that it. Tinny mini applications, pull them out and they don’t work but in the larger application they work just fine.
The logic as said is a bit different, in the configuration of the app you got one large file that has everything in it, but it’s messy, so i sacrificed a bit of my speed to put it into separate files, separated db config and routes as this gave a more clear picture of the code and you find your environment variables really fast, if you need to switch dbs
The documentation of yii could be better, some things are left up to your sense, chuncks of code are left out instead of leaving the whole things standing which would be far more handy. Luckily for he who wants to contunie with it there is a good forum with dedicated people answering even the most idiotic questions.
Posted in Technology | No Comments »
Monday, July 27th, 2009
I’m attached to codeigniter, I know my way around but codeigniter as a a easy to use but now I want something more darring and so this is it, Symfony framework, I think I’ll be doing that in my vacation that starts in about a week
Posted in me | No Comments »
Tuesday, June 30th, 2009
redirect()
Does a “header redirect” to the local URI specified. Just like other functions in this helper, this one is designed to redirect to a local URL within your site. You will not specify the full site URL, but rather simply the URI segments to the controller you want to direct to. The function will build the URL based on your config file values.
The optional second parameter allows you to choose between the “location” method (default) or the “refresh” method. Location is faster, but on Windows servers it can sometimes be a problem. The optional third parameter allows you to send a specific HTTP Response Code – this could be used for example to create 301 redirects for search engine purposes. The default Response Code is 302. The third parameter is only available with ‘location’ redirects, and not ‘refresh’. Examples:
if ($logged_in == FALSE)
{
redirect('/login/form/', 'refresh');
}
// with 301 redirect
redirect('/article/13', 'location', 301);
This was the excerpt from the codeigniter userguide but what they don’t really tell is the essential:
redirect(‘controller/function/param’, ‘refresh’);
Posted in Technology, tutorials | No Comments »
Saturday, March 28th, 2009
I’m working on a website system an facing this problem where and how to store my configurations in the database. So you want to store your configuration vars in a configuration table in the database, that’s great and fun to do too.
Why do it?
Your application becomes easier to update to a newer version, most of the time, when creating a newer version you will strip – change – add some variables for configurations, with a database it’s easier and you (or the admin) can change things on the fly.
How?
One or more tables like this:
Mysql table:
+------------------+
| config |
+------------------+
| id |
| name |
| value |
+------------------+
If you want you can add an selection column to get only the ones needed for that function but this is the best way when being in a development environment I think
Posted in tutorials | 1 Comment »
Saturday, March 14th, 2009
I must admit that I not a huge fan of Frameworks and Patterns because:
A) They make things complicated
B) Subject you to some nasty code stuff and rules
C) Because templating and Frameworks can be water and fire.
Codeigniter on the opposite has some advantage on it side for the templating stuff. This is really a short explanation for a common problem in other framework.
What to do if you want a nice folder structure or have different template styles, remember this is just a basic thing which happen to work in CI 1.7.
function index(){
$this->load->view('Themename/news/index);
}
Just add some slashes an it works so normally it should work if you would make an adaptation for themes too with a variable in it.
The next thing was kind of hard to find on the web so let me share it. It’s for when you develop with CI and your not working in the root directory of your server.
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Posted in General, tutorials | No Comments »