Jump to content
Larry Ullman's Book Forums

Edward

Members
  • Posts

    1115
  • Joined

  • Last visited

  • Days Won

    27

Everything posted by Edward

  1. Hey Antonio, when you store countries do you store them in an indexed array or do you store them all in the database with id's as such? I used to put my countries in the database but i thought it was messy so i pulled them all into an array now, but used the country code in the address column which can later be referenced.
  2. Chapter 5 looks good but i have already done that stuff now, i guess this saves people time of trying to figure it out like i did, but in some cases trying to learn the hard way sometimes works out better. At the moment i am trying to figure out how to save two models successfully i used the beforeSave() method but i had a few problems yesterday, hope to resolve the situation today. With Yii i keep having to ask myself, why, when, where and how, but any way when it works its worth it. Edit: Oh, i have learnt something new from this, you can set defaults in the validation rules, rather than adding to beforeSave() method in the model class. Makes me think this, should i sit back be lazy and wait for the cohesion. Lol even the guy who wrote the blog demo could learn a thing or two from this chapter.
  3. Edward

    My Project Diary

    Yes that would be the obvious thing to do, i know of the static arrays but for that i don't really think its the correct use as i won't be extending from the User model class and need to share the results in other classes. I'll use a private for now and move it later on, in our config section we have a main.php file that is a huge return array, the one you probably read about. I am sure Larry will cover where to add this stuff to pick up globally. I know for our own classes we add them to components and then can have the spl autoloader load them up so long as they have been configured in one of the files. Today i am just extremely happy with Yii, the first few days i was a little slow with it but now the whole framework is kicking in, the more you learn the more awesome it becomes. I would say its easy to do stuff in i built my own registration form now with data going to two models, its got email compared fields populating dropdownlists and a captcha box to prevent spam. The whole Yii is not difficult like i initially thought the blog demo they have is confusing to start off with, what i done is left it then done my own coding in Yii then when i came back it then looked easy. One thing in Yii that i am confused at today, is if we add an attribute to model for instance for captcha, email or password conpare field, even though we change rules etc the new attributes are not defined. But even the standard generated attributes i couldn't see the hard-coded versions just some commented out attributes. So anyway i had to add to my model extended active record class the attributes as public's to get the fields to work in my forms. Yii makes things really easy, as you have form scenarios so you can set which attributes form a certain form should be validated or not. You can also allow user to be in certain pages or not by authentication. I would never go back to my old coding style after learning this, as it just saves a massive amount of time and is very smart and logical. I am not scared anymore to just start building my project, i will be going forward from now, as Yii is easy to come back and change for instance if Larry does have a better way of doing something. For right now i will only work with database and code logic, i will do zero CSS or visual stuff until this is finished.
  4. Okay thanks for that, I have switched over from datetime to timestamp because they are more useful with php functions. I also read online that timestamps 32bit that finish in the year 2037 would most probably be extended to 64bit to buy them more time. This gives me a little more confidence in using them.
  5. Edward

    My Project Diary

    Well I was trying to hold the us states in a constant array but from within the address model class. I ended up using a private property to hold the array for now. Do you have any better suggestion on where to put this or will this be fine. I also have my restricted words list that I need to use in many places.
  6. Edward

    My Project Diary

    There is a problem coming up about the constant idea. I made a const for an array of states this is within my address model class. const US_STATES = array('' => 'Select State', 'AL' => 'Alabama', 'AK' => 'Alaska', 'AZ' => 'Arizona', 'AR' => 'Arkansas', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'IA' => 'Iowa', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'ME' => 'Maine', 'MD' => 'Maryland', 'MA' => 'Massachusetts', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MS' => 'Mississippi', 'MO' => 'Missouri', 'MT' => 'Montana', 'NE' => 'Nebraska', 'NV' => 'Nevada', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NY' => 'New York', 'NC' => 'North Carolina', 'ND' => 'North Dakota', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VT' => 'Vermont', 'VA' => 'Virginia', 'WA' => 'Washington', 'WV' => 'West Virginia', 'WI' => 'Wisconsin', 'WY' => 'Wyoming'); Now i get the error "Fatal error: Arrays are not allowed in class constants". So how is the best way to go about this now. Larry if you have any idea's please let us know.
  7. Also regarding this post in the Yii Book in your Yii Book Larry you put UNIQUE INDEX username_UNIQUE (username ASC), UNIQUE INDEX email_UNIQUE (email ASC) in the username table so why not INDEX login (username, pass) Should this be added as well or as those two index's already enough for putting an index on username and email when someone is logging in? Also why use: date_entered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, and not just DATE? Do we need the time in seconds exactly looking back, what is the reason for this? Sorry for all the questions. (Ah, because you can use it to minus this timestamp from other so see total time it was there)
  8. I had a go at the Zend Framework 2 tutorial i thought it might be fun but it just starts to get so horrible and ugly so i stopped i couldn't take it anymore. Code Ignitor looks easy compared to Yii, this is how Yii looks compared to Zend Framework 2 even though you are just trying to get to the same point with more trouble. I have been messing around with Yii forms, i saw some examples on how to add data to multiple models which looks easy. The trouble is the people that are submitting these examples, I don't what credit they have or even if they examples are correct. So it basically means i have to wait for you to do the same things in your Yii book and have your methods confirmed. Like Jonathon i have a large site to build and need to be 100% on these methods before proceeding forward.
  9. Edward

    My Project Diary

    Yes the constant would be useful, as i could then use it in any script which will most probably be the case. Thanks for that.
  10. Edward

    My Project Diary

    No you couldn't because usernames are restricted to 4 characters.
  11. Edward

    My Project Diary

    Friday, November 23, 2012 Worked on User.php model class and setup a more appropriate validation rule for my username's. public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( // match is the alias for CRegularExpressionValidator array('username', 'authenticateUsername'), array('first_name', 'match', 'pattern'=>'/^[A-Z \'.-]{2,50}$/i', 'message'=>'First name must be between 2 - 50 characters!'), // lenth is the aliax for CStringValidator array('last_name', 'length', 'min'=>2, 'max'=>50, 'message'=>'Last name must be between 2 - 50 characters!'), // email is the alias for CEmailValidator, CheckMX checks to see if email domain is valid array('email', 'email','checkMX'=>true, 'message'=>'Please enter a valid email'), array('address', 'length', 'min'=>2, 'max'=>100, 'message'=>'Address must be between 2 - 100 characters!'), // type is the alias for CTypeValidator, date is the alias for CDateValidator // I checked birthdays and found i couldn't enter a data lower than the year 1900 but I could enter 2013 which is not correct as no body would of been born yet. array('birthday', 'type', 'type'=>'date', 'dateFormat'=>'MM/dd/yyyy', 'message'=>'Please enter a valid birthday in the format (MM/dd/yyyy)!'), array('username, first_name, last_name, email, password, address, city, state, province, zip, country, birthday', 'required'), //array('first_name, last_name, email, city, province', 'length', 'max'=>50), //array('password', 'length', 'max'=>64), //array('address', 'length', 'max'=>100), //array('state, zip, country_id', 'length', 'max'=>20), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, username, first_name, last_name, email, password, address, city, state, province, zip, country, birthday, registration_date', 'safe', 'on'=>'search'), ); } I added the validateUsername() method to the model and added the following code in public function authenticateUsername($attribute,$params) { // Create array of restricted words: $restricted_words = array ('restricted_word1', 'restricted_word2', 'restricted_word3', 'etc'); // Create string for using in Perl-Compatible Regular Expression $restricted_words = implode ("|", $restricted_words); // Check for a valid username: if (preg_match ('/^[A-Z0-9_]{4,20}$/i', $this->username)) { if (preg_match ("/$restricted_words/", $this->username)) { $this->addError('username','Please enter a valid username'); } } else { $this->addError('username','Please enter a valid username'); } } The code worked successfully. I have been reading more on the Yii Definitive guide and now it looks like i will have no bother, i can see whats going on. I am really starting to like the way Yii does things, I am someone that really needs to concentrate on the development than MVC system coding and that is definitely what Yii allows you to do.
  12. Run the phpinfo() function on your script and check that the Magic Quotes value is off.
  13. Happy Thanksgiving to you too.
  14. Its because your magic quotes are enabled on the server therefore the characters are escaped with slashes. You can disable magic quotesin the php.ini file and check for its current status using phpinfo function. To remove escape characters from your current data use stripslashes php function which returns a string.
  15. I like that word, cohesion is a good way to describe it, yes Larry you are like a chemical binding agent, you create a universal stability. Yes your YiiBook is so good even my Chihuahua took a minute to give it a glimpse.
  16. Edward

    My Project Diary

    Thursday, November 22, 2012 Yes i made the right decision of just concentrating on Yii and dropping my other projects as Yii is taking some time to learn and is much more difficult than actual php itself even though it is php I created a user model using Gii today Yii code generator, its not really necessary to use as you could just create the model yourself but it does safe time. I have about 4 tables which are used for a user registration but what i done is put all the items into one table for now and took some out as i just wanted to practice with Yii because i have no idea how to join up tables in Yii so for simplicities sake it is best for this stage of learning. I worked with some of the validation classes that yii provides and have done edits into the User model rules() method. Some of you might find this useful. Here is what i have done so far. public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( // match is the alias for CRegularExpressionValidator array('username', 'match', 'pattern'=>'/^[A-Z0-9_]{4,20}$/i', 'message'=>'Please enter a valid username!'), array('first_name', 'match', 'pattern'=>'/^[A-Z \'.-]{2,50}$/i', 'message'=>'First name must be between 2 - 50 characters!'), // lenth is the aliax for CStringValidator array('last_name', 'length', 'min'=>2, 'max'=>50, 'message'=>'Last name must be between 2 - 50 characters!'), // email is the alias for CEmailValidator, CheckMX checks to see if email domain is valid array('email', 'email','checkMX'=>true, 'message'=>'Please enter a valid email'), array('address', 'length', 'min'=>2, 'max'=>100, 'message'=>'Address must be between 2 - 100 characters!'), // type is the alias for CTypeValidator, date is the alias for CDateValidator // I checked birthdays and found i couldn't enter a data lower than the year 1900 but I could enter 2013 which is not correct as no body would of been born yet. array('birthday', 'type', 'type'=>'date', 'dateFormat'=>'MM/dd/yyyy', 'message'=>'Please enter a valid birthday in the format (MM/dd/yyyy)!'), array('username, first_name, last_name, email, password, address, city, state, province, zip, country, birthday', 'required'), //array('first_name, last_name, email, city, province', 'length', 'max'=>50), //array('password', 'length', 'max'=>64), //array('address', 'length', 'max'=>100), //array('state, zip, country_id', 'length', 'max'=>20), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, username, first_name, last_name, email, password, address, city, state, province, zip, country, birthday, registration_date', 'safe', 'on'=>'search'), ); } Things that i need to work on tomorrow are Scenario's and i need to work on a separate validation rule for the username as there are the swear words and also copyright names which need to be blocked. I think a custom rule would be more appropriate for this matter.
  17. Been working through the YiiFramework Blog example, and then switched over to the Yii Definitive guide. It is quite a struggle trying to put things together as there are lack of examples and each topic kind of jumps about and their is a lot to take in. I am figuring it out on my own but it is taking time. So far gii was of little use to me as i could only generate a minimum of one model per time and all of my data input screens require at least 2 models. Its interesting to see Zend framework also have a version 2 now, i was checking out some of their coding style and it looked approachable. But with the time it takes with Yii it seems to be enough for me already.
  18. Check out session.gc-maxlifetime: http://php.net/manua....gc-maxlifetime Actually there is talk on how this is not reliable here is more information that should solve your problem: http://stackoverflow.com/questions/520237/how-do-i-expire-a-php-session-after-30-minutes
  19. Okay i get you, did you check that the mod rewrites are working? It could be a mod rewrite problem. Check that the .htaccess file is of file type htaccess and not just of type file.
  20. What is the /shop folder i don't see that on the coffee setup? Ive got admin / images / includes / uploads. Your base URI and URL are correct you could change define('MYSQL','includes/mysql.inc.php'); to define('MYSQL','./includes/mysql.inc.php'); if you want to tidy up.
  21. Edward

    My Project Diary

    Sunday, November 18, 2012 I completed PHP Advanced and Object-Orientated Programming book early last week, i found it easier than Larry's first PHP book. A lot has changed for me over this week, i did have another go at building a fresh mvc oop framework comparing off one online and Yii's code, this may seem easy to start of with but its just start becoming a lot more work than i had initially anticipated. The point being if i keep going with a MVC of my own i will probably spend more time developing it than making my own site which now doesn't appear to be so complicated as i may have thought with the Yii Framework. In the middle of the week i had such a big headache i was very confused what i should do now, the problem with my brain is when i try to handle and think about too much at once it seems to shut itself down and just completely refuse learning similar to shorting a wire. I was thinking of the Yii Framework, building further my procedural practice site, javascript etc and it just became too much. So i made a decision to completely change my approach, time to surrender making the MVC's and concentrate on development. Yii and the way it works is completely different to my procedural practice site, so i have also decided to just abandon this practice project completely and focus primarily on Yii. I don't have the time to build a system as well as develop a website, so that's how i can make my decision. I am now waiting on Larry's Yii Chapters coming out, i have to say myself that i kind of like the wait, it gives me time to experiment around with Yii without the rush. This Monday i will start to work through Alexander Makarov Yii 1.1 Application Development Cookbook, ive read a bit of it and its good. So with Larry's Yii Book and this book combined learning Yii should be easy i should think, I hope and we shall see.
  22. I was using a escape function to check whether magic quotes was enabled or disabled then taking appropriate action, for example public static function escapeData ($data) { global $mysqli; // Database connection. // Strip the slashes if Magic Quotes is on: if (get_magic_quotes_gpc()) $data = stripslashes($data); // Apply trim() and mysqli_real_escape_string(): return $mysqli->real_escape_string(trim ($data)); } // End of the escapeData() function.
  23. Static methods can be called directly from a class without having to make an instance of it with the new keyword. So its similar to calling a function but instead you need to call it via the class name with scope resolution operator "::" followed by the method name. For example Class Edward { static public function GetName() { echo "My name is Edward"; } } Edward::GetName(); // Echo's 'My name is Edward';
  24. You can rename the protected folder and move it outside the webroot that would be one way of doing it for separate projects. You may also want to check this link out on the YiiFramework.com website. http://www.yiiframework.com/wiki/116/moving-project-code-outside-of-webroot-plus-multiple-project-support/ But if you were working on a localhost as myself i don't think you really need to move the protected folder from the webroot as its safe already for working on.
  25. Got it today. Now i am going to get a coffee somewhere and reread foreign key constraints.
×
×
  • Create New...