EzDev.org

cakephp

CakePHP: The Rapid Development Framework for PHP - Official Repository CakePHP v3.0 - the rapid development php framework.


The processing instruction target matching "[xX][mM][lL]" is not allowed

I'm outputting XML in CakePHP. But I'm getting this error when I put my XML into a validator:

The processing instruction target matching "[xX][mM][lL]" is not allowed.

I am using correct XML layout with <?php echo $this->Xml->header(); ?> at the top then <?php echo $content_for_layout; ?>

My results are:

<?xml version="1.0" encoding="UTF-8" ?><response type='' outcome='true' message='Login successful!'>
    <user id='1234' total_number_of_completed_tasks='0' total_number_of_declined_tasks='0' total_number_of_passed_tasks='1' total_number_of_failed_tasks='1' reputation_points='99' deviant_points='0' />
        <tasks>
            <accepted>
                                <accepted_task id='4' type='Good' time_limit='500' details='Good accepted' />
                                <accepted_task id='5' type='OK' time_limit='660' details='Ok New task' />
                                <accepted_task id='9' type='Excellent' time_limit='2000' details='Great failed task' />
                                <accepted_task id='11' type='Your type' time_limit='222' details='Running and swimming all the way to Japan' />
                                <accepted_task id='7' type='Man' time_limit='744' details='My dirty task' />
                            </accepted>
            <pending>
                                <pending_task id='8' type='Women' time_limit='5151' details='Women new task' sender_id='11111' sent_date='2031-01-01 00:00:00' sender_name='Jae Choi' />
                            </pending>
            <completed>
                            </completed>
            <new>
                                <new_task id='5' type='OK' time_limit='660' details='Ok New task' />
                                <new_task id='8' type='Women' time_limit='5151' details='Women new task' />
                                <new_task id='4' type='Good' time_limit='500' details='Good accepted' />
                                <new_task id='10' type='Hello' time_limit='122' details='What is this?' />
                                <new_task id='3' type='Best' time_limit='880' details='Stop doing work!' />
                                <new_task id='11' type='Your type' time_limit='222' details='Running and swimming all the way to Japan' />
                                <new_task id='6' type='Great' time_limit='553' details='Great accepted task' />
                                <new_task id='7' type='Man' time_limit='744' details='My dirty task' />
                                <new_task id='9' type='Excellent' time_limit='2000' details='Great failed task' />
                            </new>
        </tasks>
</response>

Is there anything wrong with this?


Source: (StackOverflow)

How to unit test your API?

I'm at the point where I need to write unit tests for a REST API written using CakePHP 1.3. The API supports GET, POST and PUT requests for querying and manipulating data.

Is there any established way to test the correct input/output of an API simulating an HTTP request, using fixtures? I do not want to run actual POST/PUT requests against the live (dev) database. How can I best mock out the system to use temporary models, yet test the rest of the stack as-is?


Testing GET requests is easy enough with controller tests. However, for data manipulation the API uses HTTP headers quite extensively and also parses raw XML and JSON POST/PUT data. The controller unit test methods only mock POST data by setting $this->data in the controller, which does not allow me to properly test the API.


Source: (StackOverflow)

Set Response Status Code

I have an API call for which I need to be able to run some checks and potentially return various status codes. I don't need custom views or anything, I just need to return the proper code. If the user hasn't passed proper credentials, I need to return a 401 status. If they haven't sent a supported request format, I need to return a 400 status.

Because it's an API, all I really want to do is set the response status and exit with a simple, stupid message about why the request failed (probably using a exit). Just enough to get the job done, but I haven't been able to get this to work right. I've tried using PHP's header() and Cake's $this->header() (this is all in the controller), but although I get the exit message, the header shows a 200 OK status.

Using the code below, I get the message, but the header isn't set. What am I missing?

  if( !$this->auth_api() ) {
    header( '401 Not Authorized' );
    exit( 'Not authorized' );
  }

Source: (StackOverflow)

Unit testing in CakePHP? [closed]

I'm wondering, how do you guys unit-test in CakePHP? How do you incorporate tests in projects? What parts of a project do you test? How do you decide which parts gets to be unit-tested? Do you guys still get to finish the job before the deadline?


Source: (StackOverflow)

CakePHP: Call to a member function setFlash() on a non-object

I get the following error when trying to logout of my CakePHP app:

Notice (8): Undefined property: UsersController::$Session [APP/controllers/users_controller.php, line 75]
Fatal error: Call to a member function setFlash() on a non-object in /Users/cameron/Sites/cakeapp/app/controllers/users_controller.php on line 75

This is the code for lines 74, 75 and 76:

function logout() {
    $this->Session->setFlash('Good-Bye');
    $this->redirect($this->Auth->logout());
}

Source: (StackOverflow)

Fat models, skinny controllers and the MVC design pattern

I just read a blog post that explains MVC with a banking analogy. I have a few months of experience with web application development with an MVC framework (CakePHP), so I get the basics, but I began to see a theme that made me think I'm taking a flawed approach to where I put my logic:

  • Fat models, skinny controllers
  • Keep as much business logic in the models as possible

In my app, models are anorexic and controllers are obese. I have all business logic in the controllers and nothing besides associations and validation rules in the models.

Scanning through my controllers, I can now identify a lot of logic that should probably go in a model:

  • The app has lists, which contain items, and the items can be ranked. The sorting logic which puts the list in ranked order is in a controller.
  • Similarly, items (Item model) also have images (Image model). Each item may have a default image (designated by image_id in the items table). When an item is displayed with its images, the default image should appear first. I have the logic that does this in a controller.
  • When a list is displayed, related lists are displayed in the sidebar. The logic to determine which lists are related is in a controller.

Now to my questions:

  1. With the examples I gave above, am I on the right track in thinking that those are instances of logic presently in a controller that belongs in a model?
  2. What are some other areas of logic, common to web apps, that should go into models?
  3. I'm sure identifying this problem and changing my design pattern is half the battle, but even if I decide to take those examples I gave above and try to move that logic to a model, I wouldn't know where to begin. Can anyone point me in the right direction by posting some code here, or linking to some good learning resources? CakePHP specific help would be great, but I'm sure anything MVC will suffice.

Source: (StackOverflow)

symfony vs cakephp [closed]

What is conceptually the difference between symfony and cakephp?


Source: (StackOverflow)

Can I use one model inside of a different model in CakePHP?

Can I use another Model inside one model?

Eg.

<?php
class Form extends AppModel
{
    var $name='Form';
    var $helpers=array('Html','Ajax','Javascript','Form');
    var $components = array( 'RequestHandler','Email');

    function saveFormName($data)
    {
        $this->data['Form']['formname']=$data['Form']['formname'];
        $this->saveField('name',$this->data['Form']['formname']);
    } 

    function saveFieldname($data)
    {
        $this->data['Attribute']['fieldname']=$data['Attribute']['fieldname'];
    }

}
?>

Source: (StackOverflow)

How can I see CakePHP's SQL dump in the controller?

Is there a way that one can cause CakePHP to dump its SQL log on demand? I'd like to execute code up until a point in my controller and see what SQL has been run.


Source: (StackOverflow)

"[notice] child pid XXXX exit signal Segmentation fault (11)" in apache error.log [closed]

I am using Apache/PHP/MySQL stack.
Using as framework CakePHP.

Every now and then I get a blank white page. I can't debug it through Cake, so I peek in the apache error.log and here's what I get:

[Wed Oct 12 15:27:23 2011] [notice] child pid 3580 exit signal Segmentation fault (11)
[Wed Oct 12 15:27:34 2011] [notice] child pid 3581 exit signal Segmentation fault (11)
[Wed Oct 12 15:30:52 2011] [notice] child pid 3549 exit signal Segmentation fault (11)
[Wed Oct 12 16:04:27 2011] [notice] child pid 3579 exit signal Segmentation fault (11)
zend_mm_heap corrupted
[Wed Oct 12 16:26:24 2011] [notice] child pid 3625 exit signal Segmentation fault (11)
[Wed Oct 12 17:57:24 2011] [notice] child pid 3577 exit signal Segmentation fault (11)
[Wed Oct 12 17:58:54 2011] [notice] child pid 3550 exit signal Segmentation fault (11)
[Wed Oct 12 17:59:52 2011] [notice] child pid 3578 exit signal Segmentation fault (11)
[Wed Oct 12 18:01:38 2011] [notice] child pid 3683 exit signal Segmentation fault (11)
[Wed Oct 12 22:20:53 2011] [notice] child pid 3778 exit signal Segmentation fault (11)
[Wed Oct 12 22:29:51 2011] [notice] child pid 3777 exit signal Segmentation fault (11)
[Wed Oct 12 22:33:42 2011] [notice] child pid 3774 exit signal Segmentation fault (11)

What is this segmentation fault, how can I fix this, I have no clue and would be greatfully greatful.

UPDATE:

PHP Version 5.3.4, OSX local development
Server version: Apache/2.2.17 (Unix)
CakePhp: 1.3.10

Source: (StackOverflow)

CentOS: Enabling GD Support in PHP Installation

How do I go about enabling GD Support in a CentOS Installation?


Source: (StackOverflow)

Is PHP Object-oriented?

Is PHP an object-oriented language? If not, then what about the framework CakePHP? Is it an object-oriented MVC implementation of PHP?

Also, can a PHP application wholly built using classes be called object-oriented?


Source: (StackOverflow)

CakePHP - get last query run

I want to get the last query CakePHP ran. I can't turn debug on in core.php and I can't run the code locally. I need a way to get the last sql query and log it to the error log without effecting the live site. This query is failing but is being run.

something like this would be great:

$this->log($this->ModelName->lastQuery);

Thanks in advance.


Source: (StackOverflow)

How to get complete current url for Cakephp

How do you echo out current URL in Cake's view?


Source: (StackOverflow)

CakePHP 2.0 - How to make custom error pages?

I read that the AppError class is now for backwards compatibility and that Exceptions should be used instead. How does one go about creating custom error pages for things like 404 errors, or completely custom errors?


Source: (StackOverflow)