Cakephp sitemap for google - php

I am trying to make my first sitemap to use with google for the site that I am making. The thing is that all the displayed content is static, all the solutions i found are related with the usage of models. How can I make a sitemap for a Cake site like this? Also, is it possible to do it using the Routes, on routes.php file or does it need to be made in a more complex way?
I am using CakePHP 2.4.4.

In case you don't need any dynamic content (from the way you asked your question there is no way of knowing if you do), just create a static
sitemap.xml
in your /webroot directly
That's it.
Nothing else necessary.
Always keep things as simple as possible.

Related

PHP REST API with nested routes

I want to create a pure PHP REST API and I am quite new in backend development field, but I am experienced software developer, so some concepts are known to me.
However, after watching several tutorials on how to create REST API with PHP, all instructors were using simpler examples, where no nesting exists.
Simple Example:
GET /api/category/read.php
However, I want to create something like this:
GET /api/{user_id}/{folder_id}/{file_name}/read.php
I am struggling to find any tutorial covering this with PHP. And I have spent several hours trying to figure it out by myself by trying to modify the code I have seen in Tutorial videos. I mean if I do like they do, this would mean manually creating folders in my Project Folder for each {user_id} and so forth for each sub-folder... but I do not think that such hardcoding is the solution.
I have found some SO questions here relating closely to my question, but none have satisfying answers - makes me wonder that this if this is possible to do at all. But it seems so common (for example, I know that GitHub API has just that support /{user}/repos) so I think it should be doable.
I would be really grateful if someone could help me out how to accomplish my goal. If not else, pointing to a tutorial / documentation that does just that is equivalently appreciated!
You do not need to create the folder structure to achieve this. It would be more advantageous to use something like Apache Mod Rewrite or a framework like Laravel to help avoid the need to create the file structure you are describing and have a single endpoint for handling specific routes:
Using mod rewrite with Apache2 would work something like:
.htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^api/(.+)/(.+)/(.+)/read /api/read.php?user_id=$1&folder_id=$2&file_name=$3
This would provide the URI variables in the $_GET and $_REQUEST supergobals in /api/read.php
Using the Laravel framework you can leverage their MVC approach and create dynamic routes which can capture the URL vars and deliver them to the desired Controller endpoint:
in your routes file:
Route::get('api/{user_id}/{folder_id}/{file_name}/read', Controller#read)
in the Controller:
public function read(user_id,folder_id,file_name){ /* do stuff */ }
There is alot more to know about the specifics of MVC and using Laravel to create an API, however, they have great documentation and tutorials.
Create a PHP script that receives every request (have Apache direct all requests to it), and then process the $_SERVER['REQUEST_URI'] variable to split the path into segments, storing the parts in variables of your choice. Then dispatch the request to sub-components as necessary.

How to easily include links to other pages of my site within my PHP files?

I was wondering if there is a way to make the following process more automated (so links automatically update throughout if the links get changed).
I have a PHP site, with a front controller.
Now I'm wondering how would I go about displaying certain links (to pages) within the different PHP files? (I don't want to actually do so manually...as that would mean if the page name got changed I'd have to manually flick through all the files).
Basically what I'm looking for is a way I can include links to pages on my site easily and automatically.
I had an idea of storing them in an config array and then using some sort of wrapper/helper function in the PHP files to retrieve them from the config array and display them (but not sure if its the best way forward or if there are other ways)?
Perhaps something like how WordPress does it (although I'm not familiar with it I've heard that its using a similar technique...) as what I have is a front controller alongside a mapping array (containing the urls of the pages) - if that helps.
Appreciate all approaches and responses.
I recommend looking at some of PHP's great MVC frameworks for the best examples of using the strengths of MVC to do dynamic routing and access those routes in your views, so they update automatically.
Code Igniter, CakePHP, Zend Framework
I'm partial to CodeIgniter myself, but they all have their strengths.
I seriously suggest you look into adopting one of these frameworks if your application is complex enough to need this level of route management. No need to reinvent the wheel. Using a framework lets you spend less time messing with the nuts and bolts and more time just building your application.
Whether you use the framework or not, they are probably better examples of good object oriented design than you are likely to find in wordpress.

joomla integrate dynamic php pages to project

I am trying to integrate to a joomla project, a list of php pages setup that update their content from db, and give select options to the user, to navigate through this content. Select is also dynamic. All dynamic features work with url parsing.
For example, pageone.php gets some data from db and creates a list of selectable links to page2.php?data=fetcheddata. Page 2 gets url variables and performs queries to db to select the data.
How am I going to integrate this to Joomla? Should I make a module to include the basic php page, and how url parsing will then work? Should I make an i-frame wrapper? Please enlighten me..
You just described the way Joomla works. Depending on the content you want to present, there may already be an extension that does that, or at least does something close that can be modified. Without any more details it is hard to say, but what you are describing could probably be accomplished with a CCK http://extensions.joomla.org/extensions/news-production/content-construction. You could definitely do it with a combination of Chronoforms and Chrono Connectivity -
http://extensions.joomla.org/extensions/contacts-and-feedback/forms/1508
http://extensions.joomla.org/extensions/directory-a-documentation/faq/5661
If not, then you will probably need to code a component - http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
1) iframe solution is the easiest one. But it has its limitations...
2) you can write Joomla component (not a module) that will do the job, but I'm afraid in this case you will either have to switch to Joomla URL format... unless you find some trick how to workaround that.
If your site is not very complex a simple approach is to write your application in plain php, and integrate your Joomla template to your application so your visitors can't tell any difference. Then, you will place links from your Joomla to your application and vice-versa accordingly.
However, the best approach if you are more familiar with Joomla is to develop a component. Here you can understand the difference between Joomla Components, Modules and Plugins. Please read Joomla documentation for further understanding:
http://docs.joomla.org/Extension
http://docs.joomla.org/Component

Zend Framework – subdirectories and deprecating action within the URL

I’m in the process of learning to use the Zend Framework, and I’m therefore trying to grasp the concept of MVC. Through the Zend manual, and a very helpful Youtube video tutorial I have sort of understood the concept – still there are some things I need to clarify.
The web project I’m currently working on is a web site for an organization I’m a part of. It consists of:
The public portion, mainly consisting of information about us, a calendar and some media – mostly static information, but a couple of pages, like the calendar, will need to retrieve some data from the DB.
The internal pages, which after a login will allow users to RSVP to events and comment them as well.
The administrative controls , allows the admins to add events and manage users etc.
So far it looks like Zend wants the URL to look like this:
http?://[domain]/[controller]/[action]
So here are my questions:
Do I always have to have an action in the url, or will the lack of an action use the index-action as default?
Can I have a subdirectory to distinguish between the internal and public portions of the site: http://[domain]/internal/[controller]/[action] ?
Can this be done simply by having a subfolder within the different MVC-folders somehow?
The latter question isn’t really that important, but I’d like to separate the two portions of the site somehow.
Do I always have to have an action in the url, or will the lack of an action use the index-action as default?
A controller can have a default action which is triggered when no action is specified in the URL. Look for default action or index action.
Can I have a subdirectory to distinguish between the internal and public portions of the site: http://[domain]/internal/[controller]/[action] ?
Yes you can have, but I assume subdirectory refers to your URL, not to the actual file-layout on the server. You can do so by just having a controller per "subdirectory".
Can this be done simply by having a subfolder within the different MVC-folders somehow? The latter question isn’t really that important, but I’d like to separate the two portions of the site somehow.
You can separate per controller and you can even separate with modules. As far as I know of modules in zend-framework, this will all be in it's own sudirectory per module.
I think you're especially looking for Using a Conventional Modular Directory Structure.
The questions you are asking are in the area of routing which generally means: Given a URL on which the HTTP request is being made:
Which controller should be instantiated?
Which action on that controller should be run?
What parameters should be passed to the action?
The routing docs in the ZF Manual explain how routing works by default and how you can specify your own routing. But looking at them now, I don't think they do a great job of introducing the subject matter for a first time user. This post might be better, though it is only a single, simple example.

How to modularize CodeIgniter?

Well, I have been thinking a lot about the first real CodeIgniter site I am coding. I want to modularize the site in such a way that I have a controller that formats the navbar, one that formats a multipurpose right column, and one that formats the content area.
My idea is to have a controller for each state of any part of the site (an example would be the right column, it would have 3 states; new posts, related posts, and search filters). I would also have the content area be many different states aswell (things like search results, view post, new posts, etc).
The problem is that I can't find a way to take multiple controller outputs and compile it into a single template (notice, I said controllers, not views).
I have seen the HMVC extension, but that is going to far for my first site, and am hoping for a more simplistic solution (unless you can prove me wrong, and show that HMVC is easier than what I've seen).
This seems a little wonky to me in an MVC model.
If you're using a single stateful view for your right panel that might change state based on input (i.e. which page the user is currently on), then I would add a model for the panel. The controller's action would be responsible for setting the correct model state (i.e. "you're in home page state"). The model could be responsible for telling the right panel view which child views to load.
That's how I'd probably implement something like that anyway. HMVC seems overkill and with this example, wouldn't be used as intended.
For what you're trying to accomplish the matchbox module suggested in the comments seems way overkill. I don't think that using controllers to format each of these areas is a very good approach to take.
Usually people who want the type of functionality that you're describing when working with CodeIgniter end up using a template library. There are several open source template libraries for CodeIgniter that can easily be found with a google search for "codeigniter template library".
I've never used any of them so I will not recommend any particular library. However the app that I'm working on has borrowed some ideas from Phil Sturgeon's template library. You may not find an exact match to features that you need but at least you'll be able to draw some inspiration from solutions that others have come up with.

Categories