I am developing REST API using Phalcon. The application will have multiple modules like Users, Company, Contacts and so on. Each of these modules have their own tables for storing data. Moreover each module have their own defination file which mentions what fields to show in API response. I am pretty new to Phalcon, i just started learning Phalcon, and I need help regarding how i should structure the application so that this code won't give me future problems, or if I'm missing something or if the code could be abstracted more then that would be great.
Directory Structure as planned:
app/
MyAPI/
MyAPIControler.php
library/
controller.php //master controller where all controllers inherit from
model.php //master model where all models inherit from
utilities.php
MyAPI/
models/
User.php
Contacts.php
Company.php
Myapi.php
/config
config.php
routes.php
index.php
I want all database related queries of each module to reside in their own models. API URL say for listing of records will be
http://api.example.com/MyAPI/V2/contacts/list or /MyAPI/V2/users/list. Similarly API URL for creating records will be http://api.example.com/MyAPI/V2/contacts/add or /MyAPI/V2/users/list
Please advise how i should proceed
The project folder structure would be better if it's something like this,
app/
config/
controllers/
forms/
library/
models/
views/
cache/
public/
css/
img/
schemas/
The folder names are self explanatory. Since your trying to make a REST API, you can remove the public folder along with css and img in it. You can also set the default render to be json in the base controller and have the other controller's extend it.
Related
I'm developing a new Hugo site and in this case I thought to create also a template so.I can use for future site.
Well in the template there are tons of vendor files and library because depending of the pages that the site will implement these library will be used. The problem is on the deploy. For example I use Line icons library that has a lot of .png files. (For example 200 files).
Well in the template I put all the files but could happen that in the site that implement this template I use only five icons. Is there a way that look around the final HTML and the usage of the icons and delete in the public folder the not necessary files?
Not directly.
You would need to add an utility script to your template, in order for any user implementing said template to be able to call this script on demand.
That script should then be able to:
analyze the HTML files generated in public_html
cleanup the icons accordingly
I have a zend framework project, all written in one Module. Under this Module you find a controller directory, Model directory and view directory. I am looking for a perspective to devide this Module into many, each with its controllers, models and views. would you supply me with some references to read more about this.
Thanks in advance.
You should not divide your module, but introduce several modules. Each module has its own config, src and view folder. Inside the src folder is another folder (same name as Module) and in this src folder you find controller, view and model folders (and more depending on the project).
So something like this:
As far as I know this is the correct layout in a ZF2 application.
You can also read on folder structure in the ZF2 documentation.
And on ZF2 project structure here
And on setting up a module here in the ZF2 user guide
I am using Bootstrap for some basic styling to a CRUD app in Sinatra. While the assets in the public folder load as usual on all pages, they don't load when I am browsing a particular record in my database.
For example, http://localhost:4567/songs loads all stylesheets and assets, but not http://localhost:4567/songs/1.
In my console, the page seems to be trying to find the css file in /songs folder, which I am not sure why its doing that.
http://localhost:4567/songs/bootstrap.css
Any help or pointers would be appreciated.
My main.rb file: http://pastie.org/8543319
My song.rb class file: http://pastie.org/8543312
Provide absolute path for assets in your views.
I've started using Zend framework, and Im following this simple Zend form tutorial. The form is located in application/forms directory I have included the Zend framework in the Path (by going to computer properties). However when i access form.php page, i get this error:
Fatal error: Class 'Zend_Form' not found
I have also tried by copying the Zend folder from the Zend framework in the library folder of the application, however error still remains same. Thanks.
It sounds like you are confusing two notions: the system path and the include path.
The system path is an operating system concept. When you ask the OS to execute a command, the system path is a list of places to look for the executable.
In contrast, the include path is a PHP concept that tells PHP a list of folders in which to look for files invoked by PHP include/require statements.
Any path that you find in "Computer > Properties" is almost certainly the OS-level system path. What you need to do is to make sure the Zend folder on the PHP include path, either by moving the Zend folder or by modifying PHP's include path to include a point to the Zend folder.
In a typical ZF app, the include folder is set in index.php (the front controller). So, the only explanation for not finding Zend_Form is that the autoloader is not being instantiated.
If you are using Zend_Application, this happens automatically. However, it seems like you are bypassing public/index.php and the whole Zend_Application instantiation by trying to directly "access" a file called form.php directly. If this file contains only the definition of your form (extending Zend_Form), then the absence of autoloading could easily explain the error message you are getting.
I'd try instantiating the form in a controller action, by which time in the request processing cycle, the autoloading is probably already in place.
[At that point, given the file locations you cite, we might run into a resource-loader issue, but that's a somewhat different issue that can be handled by instantiating a Zend_Application_Module_Autoloader in your Bootstrap.]
It looks like you do not use Zend_Loader. You should focus on it.
You can also manually in your custom form class include Zend_Form class.
I don't have permission to change the document root the /public/ directory so how should I set up my Zend Framework application to run from the current root directory? Using the Zend Framework 1.8 command line tool, I don't know if there is a way to tell it to create a directory structure this way.
If you can access only the upper level of web (i.e. - public), you should set index there and the whole application folder too. Create a .htaccess with
Deny from all
And put it into your /application.
Your configuration will be:
/application
/library
index.php
The simplest way without changing a lot of configuration, is to put everything in the public folder you mention into your public_html folder, then place all the other contents, like the application, and library folders into the directory up from public_html.
You can also throw everything into your public_html folder, although that is not recommended. Each class has options to provide a different path. For example on the Front_Controller, you can set the Controllers directory to wherever you want. There are options to specify different paths, but if you follow convention it is done for you.
Just use the quickstart guide and adjust according to it. Zend_Tool is still experimental anyway. Let me know if this helps.
So here's what I ended up doing:
Download the Quickstart sample code.
Move everything in public up to the main directory, along side application, library directories.
Alter include paths to library and application in index.php to point to the correct locations
I think that was all I had to do. ZF new how to the rest.
I don't think this is ideal however, as already mentioned, application directory becomes accessible from the web, but for now, it's getting the job done.