Example #1
0
 /**
  * Performs a delete on given scaffolded Model.
  *
  * @param array $params Parameters for scaffolding
  * @return mixed Success on delete, error if delete fails
  * @access private
  */
 function __scaffoldDelete($params = array())
 {
     if ($this->controller->_beforeScaffold('delete')) {
         if (isset($params['pass'][0])) {
             $id = $params['pass'][0];
         } elseif ($this->_validSession) {
             $this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)));
             $this->controller->redirect($this->redirect);
         } else {
             return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)), '/' . Inflector::underscore($this->controller->viewPath));
         }
         if ($this->ScaffoldModel->delete($id)) {
             if ($this->_validSession) {
                 $this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id));
                 $this->controller->redirect($this->redirect);
             } else {
                 return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
             }
         } else {
             if ($this->_validSession) {
                 $this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id));
                 $this->controller->redirect($this->redirect);
             } else {
                 return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
             }
         }
     } elseif ($this->controller->_scaffoldError('delete') === false) {
         return $this->__scaffoldError();
     }
 }
Example #2
0
/**
 * Sends a message to the user. Either uses Sessions or flash messages depending
 * on the availability of a session
 *
 * @param string $message Message to display
 * @return void
 */
	protected function _sendMessage($message) {
		if ($this->_validSession) {
			$this->controller->Session->setFlash($message);
			$this->controller->redirect($this->redirect);
		} else {
			$this->controller->flash($message, $this->redirect);
		}
	}
 /**
  * @see Controller::flash()
  * @param $msg
  * @param $url
  * @param int $pause
  * @param string $layout
  * @return void
  */
 public function flash($msg, $url, $pause = 2, $layout = 'flash')
 {
     if (!$this->useFlash) {
         $this->Controller->redirect($url);
         return;
     }
     $this->Controller->flash($msg, $url, $pause, $layout);
 }
 /**
  * Sends a message to the user. Either uses Sessions or flash messages depending
  * on the availability of a session
  *
  * @param string $message Message to display
  * @param string $element Flash template to use
  * @return void
  */
 protected function _sendMessage($message, $element = 'default')
 {
     if ($this->_validSession) {
         $this->controller->Flash->set($message, compact('element'));
         return $this->controller->redirect($this->redirect);
     }
     $this->controller->flash($message, $this->redirect);
 }
Example #5
0
 /**
  * Performs a delete on given scaffolded Model.
  *
  * @param array $params
  * @return success on delete error if delete fails
  * @access private
  */
 function __scaffoldDelete($params = array())
 {
     if ($this->controllerClass->_beforeScaffold('delete')) {
         $id = $params['pass'][0];
         if ($this->controllerClass->{$this->modelKey}->del($id)) {
             if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
                 $this->controllerClass->Session->setFlash('The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id . ' has been deleted.');
                 $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath));
             } else {
                 return $this->controllerClass->flash('The ' . Inflector::humanize($this->modelKey) . ' with id: ' . $id . ' has been deleted.', '/' . Inflector::underscore($this->controllerClass->viewPath));
             }
         } else {
             if (isset($this->controllerClass->Session) && $this->controllerClass->Session->valid != false) {
                 $this->controllerClass->Session->setFlash('There was an error deleting the ' . Inflector::humanize($this->modelKey) . ' with the id ' . $id);
                 $this->controllerClass->redirect('/' . Inflector::underscore($this->controllerClass->viewPath));
             } else {
                 return $this->controllerClass->flash('There was an error deleting the ' . Inflector::humanize($this->modelKey) . ' with the id ' . $id, '/' . Inflector::underscore($this->controllerClass->viewPath));
             }
         }
     } elseif ($this->controllerClass->_scaffoldError('delete') === false) {
         return $this->__scaffoldError();
     }
 }
    /**
     * testFlash method
     *
     * @return void
     */
    public function testFlash()
    {
        $request = new CakeRequest('controller_posts/index');
        $request->webroot = '/';
        $request->base = '/';
        $Controller = new Controller($request, $this->getMock('CakeResponse', array('_sendHeader')));
        $Controller->flash('this should work', '/flash');
        $result = $Controller->response->body();
        $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>this should work</title>
		<style><!--
		P { text-align:center; font:bold 1.1em sans-serif }
		A { color:#444; text-decoration:none }
		A:HOVER { text-decoration: underline; color:#44E }
		--></style>
		</head>
		<body>
		<p><a href="/flash">this should work</a></p>
		</body>
		</html>';
        $result = str_replace(array("\t", "\r\n", "\n"), "", $result);
        $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
        $this->assertEquals($expected, $result);
        App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)));
        $Controller = new Controller($request);
        $Controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
        $Controller->flash('this should work', '/flash', 1, 'ajax2');
        $result = $Controller->response->body();
        $this->assertRegExp('/Ajax!/', $result);
        App::build();
    }
Example #7
0
 public function flash($message, $url, $pause = 1)
 {
     parent::flash($message, router_url_language($url), $pause);
 }
Example #8
0
    /**
     * testFlash method
     *
     * @access public
     * @return void
     */
    function testFlash()
    {
        $Controller = new Controller();
        $Controller->flash('this should work', '/flash');
        $result = $Controller->output;
        $expected = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>this should work</title>
		<style><!--
		P { text-align:center; font:bold 1.1em sans-serif }
		A { color:#444; text-decoration:none }
		A:HOVER { text-decoration: underline; color:#44E }
		--></style>
		</head>
		<body>
		<p><a href="/flash">this should work</a></p>
		</body>
		</html>';
        $result = str_replace(array("\t", "\r\n", "\n"), "", $result);
        $expected = str_replace(array("\t", "\r\n", "\n"), "", $expected);
        $this->assertEqual($result, $expected);
        App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS)));
        $Controller =& new Controller();
        $Controller->flash('this should work', '/flash', 1, 'ajax2');
        $result = $Controller->output;
        $this->assertPattern('/Ajax!/', $result);
        App::build();
    }