Added: 1 year ago
From: andrewperk
Views: 24,242
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (34)

Sign In or Sign Up now to post a comment!
  • Thanks mate, I was quite desperate trying to understand how properly use find(). You made everything look pretty easy. Props to you! :)

  • Andrew, the docs say to use the form Modelname.fieldname, does it make any particular difference? Thanks

  • @CamiloSanchez1979 You only need to specify the Model.field if you are wanting to do a condition search where you are checking if something is equal to, less than, etc or if you are wanting to specify which fields should be returned from the query. You do this by passing in an array as the second param to the find method. In this video we are wanting to find all posts and have no conditions to be met. Thus we only need to pass in the type of the find query. 

  • nice tutorial thanks..^^

  • i did the brackets and it worked fine but the index wont show in the view in my browser .. it shows blank page........ any way i'll recheck my code again

    thanx very much for ur help sir i appreciate it

    god bless u :)

  • i did everything u said ...but nothing shows in the view in web browser ... and it gives me an error in line of endforeach;

    thats is :)

  • @goldd85 I'm sorry I don't know how to help you with this one. You must have done something wrong. Writing a foreach loop is very simple, no one else has had this problem. All I can suggest is recheck your code or try writing the foreach loop the normal way rather than using the shorthand way (ex. Use curly brackets {} and not the : colon syntax)

  • have an error in endforeach statement....what is the solution??

  • @goldd85 I have no way to provide you a solution since you did not provide an error.

  • marvelous video :)

  • You didn't show your model in this video

  • @runrunforest1 It's a continuation of the previous 2 videos. You don't need to see the model in order to use it's find method. The model is completely blank at this point anyways besides just declaring it as a class.

  • Hi dude. i have a problem. im already check all the code againts yours... it's exactly the same but i got this message

    Fatal error: Call to a member function getAttribute() on a non-object

    i can`t find a solution, maybe my php config is the problem, my server is on dreamhost.

    Can you give me a tip?

  • @fullmentalmx At what point did you get this error? Did the code from video #2 work on your server? Does this work locally for you?

  • @andrewperk i got this error when i try to view all messages. i dont have the server locally but i will try to config it and check. min [5:31]

    i find this post cakephp.1045679.n5.nabble.com/­2-0-0-dev-sturtup-problem-td33­22343.html and tried to update cake to version 2.0 but that doesn't work.

  • Hello Andrew..your tutorials are great...Instead of using find(), can we directly use select query and fetch the data to display it in views.I am having difficulty as i need to combine 5 tables using join to display the data.So i directly used select query. eg.

    $sql="select id,name,email from users";

    $posts= $this->Post->query($query); $this->set('posts',$posts);

    when i gave this i got an error in the views....

    Undefined index: Post [APP\views\posts\index.ctp, line 27] can you explain that?

  • Thank you for getting back to me, I Tried it both ways and even went to your site and downloaded to the Source code. Its very strange. Won't connect to the DB although the cake config page says it can. I am using wamp if it makes any difference. is there some place I can post my code for you to look at or perhaps I could post it on my site. Would rather just email it if I could. But I understand if you would rather not.

  • I am having trouble...

    I am getting the following error:

    Parse error: parse error in ~\tut_blog\app\views\posts\ind­ex.ctp on line 10

    Can't seem to see what i did wrong

  • @kazigmal Hard to say without myself being able to look at it. But maybe you used a semicolon using the different foreach syntax. In the statement where I say foreach($posts as $post): That should be a colon not a semicolon. In the video it's hard to tell what it is. Make sure you referencing the $post variable now inside the foreach loop rather than $posts.

  • I figured it out... It seems that the problem was with my PHP environment... I did not enable short tags...

    Once I did... everthing was fine.

  • Why the following code is not able to produce the desire result when i changed the "Post to post" ?

    uppercase to lowercase

    $this->post->find('all')

  • @yewei123sg That's just how it is, it requires it to be capitalized when referring to a models method.

  • thanks for posting this video

  • foreach () ... endforeach does not work..

    i did it this way and it worked..

    forearch () {

    }

    can u explain why this is so?

  • @erhmirhnem

    Using the endforeach; requires that you have short tags enabled in your php .ini file. You probably have it disabled. Using foreach with braces works just fine too, you can either one you feel comfortable with.

  • @andrewperk .. thanks soo much.. ur da mayne... stay blessed...

  • Consise, understable, easy, quick.... its all i want in a vid tut. Perfect

  • I like them too.Indeed, it's very clear and fast tutorial I ever seen.Thanks man

  • Believe me, you'll become a legend. Congrats.

  • wow, this is a great tutorial! very clear and understandable with good contextual information so i understand exactly what you are doing. i am very impressed and looking forward to learning more methods from you!

  • @yagazuzy Thanks, I'm glad you liked it. I should have part 4 up tonight or early tomorrow.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more