I am new to CakePHP, my first framework. I've been doing some of the basic tutorials provided in the documentation, and I often come across a method or an attribute that I want to know more about. For example:
//App/Model/User.php
...
public function isOwnedBy($post, $user) {}
My question is, how do I find more details about any attribute or method? I've tried searching using the internal search but no results. I've also been googling in the hope that that might give me results, but nope. I've tried using the API to look it up, but no results either. Am I doing something wrong?
Understanding what exactly a method does, and an attribute is, makes it much easier to follow the tutorials in my own experience. Especially in the Authentication/Authorization stage, where lots of methods and attributes get introduced without too much explanation.
If it's part of the core API, then it's documented in the API docs. Parts of the API are also described in detail in the CookBook. To get a more detailed grasp on what's going on you can of course always have a look at the source code.
That specific method however is a custom model method from the CookBooks Simple Authentication and Authorization Application example, so you won't find anything about it in the API documentation as it's not part of the core API.
In case the code provided in the examples isn't documented well enough for you to understand it, then you can always ask for further explanation/help, for example in the groups, the chat, etc (see http://community.cakephp.org/), and also here on Stack Overflow if you have a specific questions.
Related
I am currently building an API using Laravel, and in order to learn Laravel as quickly as I possibly can, I am using another person's project to teach me the basics.
I have come across a bit of code that I cannot get my head around and was hoping that someone may be able to tell me what it is actually doing?
Here is the full code:
User::min()->find($this->id)->devices()->get();
Most of the above is obvious to me as I have been building this project for a month and resultantly, am very familiar with models. But the following snippet I cannot understand:
User::min()
Is min() the predefined PHP function, or is it a custom method on the model? Either way, how does it affect the retrieval from the model?
EDIT: Check the User model and see if there's a scopeMin() defined there.
I realize similar questions have been asked and answered, but bear with me because I haven't found the answers satisfactory in that, I still don't see how to solve my problem. I just understand "you shouldn't do that". Fine, but can someone help me understand how to accomplish this (seemingly) simple task?
I have a number of entities (i use that term loosely, these are not doctrine entities, they are simply from-scratch data models that load data from an external API). I would like some of these entities to have a getUrl() function, so that anywhere I encounter them, I can simply call $entity->getUrl() and have a proper and consistent url to use.
Initially I was constructing these url paths by hand, but then realized, "I should be using the urls defined in the routing configuration to generate these. Then they will REALLY be guaranteed to be consistent site-wide". So I search and come across these answers on SO that say "Your entities shouldn't know about anything but other entities" and "Create a separate service." Well, fine, but I still want an $entity->getUrl() method to call! Is it impossible to achieve this and still adhere to basic principles? Can someone explain to me how I can get it done? If I create a separate service, I still don't seem to be able to accomplish my goal, since "you shouldn't access services from inside entities."
What's a guy to do? Can anyone help me understand?
If I have a REST based service written in the Symfony [symfony-project.org] framework (i.e. PHP), is there any decent tools/frameworks out there that will parse my code and generate API documentation?
The Java based framework enunciate has documentation capabilities similar to what I need, you can view an example of this here: http://enunciate.codehaus.org/wannabecool/step1/index.html.
I understand the premise of REST based services are supposed to be self evident, however I was after something that would generate this documentation for me without the need to manually write up all my endpoints, supported formats, sample output etc.
Thanks
Not sure if you've seen Swagger before. They seem to have a PHP compatible version, though I can't really vouch for it personally. It does some automatic API documentation generation comparable to enunciate, though it does look like it requires some heavy manual documentation via PHP comments. That being said, I think the manual effort will be the same or less than making your own via wiki pages, and the output is much, much nicer.
Just as a factoid, it looks like Enunciate has indefinite plans to eventually support other platforms, but the relevant Jira ticket is currently Open waiting for a sponsor to take on the work.
From the ENUNCIATE-356 Jira ticket:
The first step to supporting other languages is to decouple the Enunciate model from the Java model. This work is being tracked and logged at ENUNCIATE-584. Unfortunately, it never made it out of the investigate phase because of how heavy it is. Unless a sponsor for the work is found, I don't anticipate taking that heavy load on anytime soon.
Edit:
Found a similar question where someone mentions a GitHub project dedicated to Swagger+Symfony2. This other question is the same, but no additional information.
To my knowledge there is no way to automate the documentation of media types.
If you are using a media type like XHTML then a web crawler like Google sitemap may produce some useful output to show the relations between your resources.
Wher can I find a good documentation on these two PHP files and a more detail & indepth use of each function?
Facebook documentation is... not informatitve enough. lol
I feel your pain.
facebookapi_php5 is mainly each API method.
facebook is mainly for session/auth.
The best place I've found so far is the developer forums, but it is mainly questions without answers.
Since Facebook is always changing their API, the documentation is inevitably lacking and/or out of date. If you are looking up viral information, you going to find a lot of pages that say they have been deprecated.
My most used pages are:
http://wiki.developers.facebook.com/index.php/API
http://wiki.developers.facebook.com/index.php/FBML
http://wiki.developers.facebook.com/index.php/FBJS
You can play around with the API here:
http://developers.facebook.com/tools.php?api
But in the end, just about everything in those files gets passed through the post_request function in the facebook_php5_restlib file. That's where the curl function is for "posting" to Facebook. You can always capture what's going on in that function.
Aside from the PEAR repository, which I find often has quite messy code with a lot of it using old or deprecated methods and techniques, I was wondering if there was a great place to find simple (and not so simple) PHP examples of some generic functions and good pieces that people have written.
A good example would be the PEAR spreadsheet module I used a while back. The thing worked but it was written quite messily and if I remember correctly, in PHP 4.
I'd like to find something with well written and well documented code that I can refer to and see exactly how people are doing things and why they are doing things that way.
The PHP manual's as good a place to start as any, I've particularly found some of the comments on there helpful.
There's also The PHP Resource Index, which is mostly a jumping off point to other projects' websites.
Don't forget to look at questions tagged PHP on stackoverflow.
Have a look at PHP Classes. They have a large selection of classes, all with user ratings.
There's also Zend Framework spesific ZF Snippets site
Github is another good resource, more often than not it is polished code that is updated frequently.
Getting classes from other people is all well and good but keep upgrade-ability in mind, if i'm using someone else's class and need to tweek it i always extend from it.