Cakephp Blog Tutorial Part 3 – Using the Find Method

18 04 2011

This is a tutorial using cakephp for building a blog. In this tutorial we use the model’s Find method for retrieving all data from the database. You can download the source files for this tutorial at http://www.andrews-custom-web-design.com

In this quick screencast I continue the series on custom theming. I will be talking about .tpl.php files in the videos.
Video Rating: 4 / 5


Actions

Information

47 responses

18 04 2011
fullmentalmx

@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-td3322343.html and tried to update cake to version 2.0 but that doesn’t work.

18 04 2011
andrewperk

@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?

18 04 2011
fullmentalmx

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?

18 04 2011
caribeansong

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 [APPviewspostsindex.ctp, line 27] can you explain that?

18 04 2011
slanten123

Thx, you’re good at explaining stuff!

18 04 2011
kazigmal

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.

18 04 2011
kazigmal

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.

18 04 2011
andrewperk

@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.

18 04 2011
kazigmal

I am having trouble…

I am getting the following error:
Parse error: parse error in ~tut_blogappviewspostsindex.ctp on line 10

Can’t seem to see what i did wrong

19 04 2011
andrewperk

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

19 04 2011
yewei123sg

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’)

19 04 2011
yewei123sg

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’)

19 04 2011
sivayuvasamrat

thanks for posting this video

19 04 2011
erhmirhnem

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

19 04 2011
andrewperk

@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.

19 04 2011
erhmirhnem

foreach () … endforeach does not work..

i did it this way and it worked..
forearch () {

}

can u explain why this is so?

19 04 2011
urbanvideostv

thanks!
you rock!

19 04 2011
zarnos

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

19 04 2011
ucha19871

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

19 04 2011
BettyBoop186

Believe me, you’ll become a legend. Congrats.

19 04 2011
andrewperk

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

19 04 2011
yagazuzy

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!

19 04 2011
syedm4u

u r super boy

19 04 2011
aklinci

Great tutorial, very helpful for me🙂

19 04 2011
sivayuvasamrat

hi great video but in this video you voice is not coming

19 04 2011
martingoldstein9

So grateful for these tutorials. Very helpful. Thank you so much!

19 04 2011
ALIENwoods

best drupal theme tutorial video ever!

19 04 2011
samoa92064

good stuff mate!@ carry on!

19 04 2011
Jsnandrsn

He’s using Coda for OSX

19 04 2011
MogulSuccess

GREAT JOB REAL HELP!

19 04 2011
lockonfighter1

Nice tutorial tom

19 04 2011
SmokeJeffy

tnx

19 04 2011
ironmonnkey15

gotta say this is the best tutorial out there. It is slower paced and he doesn’t miss a thing. Really helped out. Thanks man.

19 04 2011
nymphsU2

I’ve been watching from part 1. You are so impressive! Well explained such complicated program. I’ve seen many videos for theming and drupal, but so far you are the only one did it from scratch! Thanks for your tutorials. Great videos.

19 04 2011
cphoover11

What are u using to code in? Great video!!

19 04 2011
Kodetze

Thank you for your tutorials!

19 04 2011
dancourse

You’re a freaking star doing these! Turn your your mic. up though man, want to hear you easier.

19 04 2011
rnuthman

incredible tutorials.. awesome man

19 04 2011
dineshkola

its toooo good .. thanks a lot for sharing this video. it helped me a lot .

19 04 2011
Marfordel

I love drupal but i ain’t clever enough to use it !!
Thanks so much for this- so far drupal has been horribly frustrating. but this tut. is fantastic..
thanks again

19 04 2011
AslanAmirov

thx for tutorial. hello to u fron russia. i wanted to learn more about drupal and i’m glad to find some video thx again. (sory 4 my english🙂

19 04 2011
knightyknight

Smart cookie, nice one mate. Well done! Saved me a lot of time too!

19 04 2011
vsmart8

Thanks for the video. I learned a lot.

19 04 2011
Basiclline334ak

Hi Tom thanks for ths tut an shareing greetings your make a good job

19 04 2011
noparatchock

thank you so much !! u r the best !!

19 04 2011
semiplay

Great tutorial! I copied the code showed here and had an error (Object of class stdClass could not be converted to string) which was referring to the language variable in line 2. I found a reference in a forum and fixed it by changing “print $language” to “print $language->language;”

This series has helped me a great deal in learning Drupal theming. Thanks Tom!

19 04 2011
Tantoin

You are a smart kid, I am proud of you, keep learning and sharing, I appreciate what you are doing for us older people.




%d bloggers like this: