Bonjour.
J'ai un prolème sur cakephp.
l jour 1.
J'ai cette erreur :
( ! ) Parse error: syntax error, unexpected T_PUBLIC in C:\wamp\www\Project\cake_php_blog\app\Model\Post.php on line 19
Call Stack
1 0.0011 701624 {main}( ) ..\index.php:0
2 0.0618 2775728 Dispatcher->dispatch( ) ..\index.php:96
3 0.1022 3960440 Dispatcher->_invoke( ) ..\Dispatcher.php:88
4 0.1057 4029848 Controller->invokeAction( ) ..\Dispatcher.php:106
5 0.1058 4031456 ReflectionMethod->invokeArgs( ) ..\Controller.php:476
6 0.1058 4031488 PagesController->admin_edit( ) ..\Controller.php:476
7 0.1059 4031688 Controller->__get( ) ..\Controller.php:48
8 0.1059 4031688 Controller->__isset( ) ..\Controller.php:396
9 0.1060 4031736 Controller->loadModel( ) ..\Controller.php:358
10 0.1090 4132808 ClassRegistry::init( ) ..\Controller.php:673
11 0.1096 4135536 class_exists ( ) ..\ClassRegistry.php:135
12 0.1096 4135848 App::load( ) ..\ClassRegistry.php:0
Voici mon code de Post.php
<?php
class Post extends AppModel{
public function afterFind($data){
foreach ($data as $k=>$d) {
foreach($data as $k=>$d){
if(isset($d'Post']'slug']) && isset($d'Post']'id'])){
$d'Post']'link'] = array(
'controller' => 'pages',
'action' => 'show',
'id' => $d'Post']'id'],
'slug' => $d'Post']'slug']
);
}
$data$k] = $d;
}
return $data;
}
public function beforeSave(){
debug($this->data);
if(empty($this->data'Post']'slug']) && isset($this->data'Post']'slug']) && !empty($this->data'Post']'name']))
$this->data'post']'slug'] = strtolower(Inflector::slug($this->data'Post']'name'])
));
return true;
}
}
}
?>
Merci :(
Je pense avoir trouvé, tu as aussi une faute au niveau de tes accolades.
ton accolade ligne 26 met la en ligne 18 comme ceci :
<?php
class Post extends AppModel{
public function afterFind($data){
foreach ($data as $k=>$d) {
foreach($data as $k=>$d){
if(isset($d'Post']'slug']) && isset($d'Post']'id'])){
$d'Post']'link'] = array(
'controller' => 'pages',
'action' => 'show',
'id' => $d'Post']'id'],
'slug' => $d'Post']'slug']
);
}
$data$k] = $d;
}
return $data;
}
}
public function beforeSave(){
debug($this->data);
if(empty($this->data'Post']'slug']) && isset($this->data'Post']'slug']) && !empty($this->data'Post']'name']))
$this->data'post']'slug'] = strtolower(Inflector::slug($this->data'Post']'name'])
));
return true;
}
}
?>
Là, tu avais la fonction beforeSave dans la fonction afterFind.
Essaye avec ça.
Tu as vraiment un soucis de parenthèse, tu as enlevé la parenthèse de la ligne 22 au lieu de celle de la ligne 23
remplace ta fonction par celle ci,
public function beforeSave(){
if(empty($this->data'Post']'slug']) && isset($this->data'Post']'slug']) && !empty($this->data'Post']'name']))
$this->data'Post']'slug'] = strtolower(Inflector::slug($this->data'Post']'name']));
return true;
}
Salut,
tu as une parenthèse en trop ligne 22 ou ligne 23.
Essaye de voir si cela vient de là.
Merci avec ton code je n'est plus l'érreur mais une autre :(
( ! ) Parse error: syntax error, unexpected ')' in C:\wamp\www\Project\cake_php_blog\app\Model\Post.php on line 24
Call Stack
# Time Memory Function Location
1 0.1789 4583376 ErrorHandler::handleException( ) ..\ErrorHandler.php:0
2 0.2042 4784808 ExceptionRenderer->render( ) ..\ErrorHandler.php:127
3 0.2042 4785512 call_user_func_array ( ) ..\ExceptionRenderer.php:170
4 0.2042 4785544 ExceptionRenderer->_cakeError( ) ..\ExceptionRenderer.php:170
5 0.2045 4786680 ExceptionRenderer->_outputMessage( ) ..\ExceptionRenderer.php:192
6 0.2046 4786680 Controller->render( ) ..\ExceptionRenderer.php:267
7 0.2200 5141256 View->render( ) ..\Controller.php:901
8 0.2915 6930368 View->renderLayout( ) ..\View.php:376
9 0.2929 6931856 View->_render( ) ..\View.php:414
10 0.2936 6985328 include( 'C:\wamp\www\Project\cake_php_blog\app\View\Layouts\default.ctp' ) ..\View.php:598
11 0.2940 6985408 View->element( ) ..\default.ctp:14
12 0.2948 6987160 View->_render( ) ..\View.php:320
13 0.2954 7039600 include( 'C:\wamp\www\Project\cake_php_blog\app\View\Elements\menu.ctp' ) ..\View.php:598
14 0.2955 7040288 Object->requestAction( ) ..\menu.ctp:1
15 0.2998 7045888 Dispatcher->dispatch( ) ..\Object.php:88
16 0.3016 7053016 Dispatcher->_invoke( ) ..\Dispatcher.php:88
17 0.3025 7055296 Controller->invokeAction( ) ..\Dispatcher.php:106
18 0.3027 7056744 ReflectionMethod->invokeArgs( ) ..\Controller.php:476
19 0.3027 7056776 PagesController->menu( ) ..\Controller.php:476
20 0.3027 7056976 Controller->__get( ) ..\Controller.php:10
21 0.3027 7056976 Controller->__isset( ) ..\Controller.php:396
22 0.3028 7057024 Controller->loadModel( ) ..\Controller.php:358
23 0.3029 7057960 ClassRegistry::init( ) ..\Controller.php:673
24 0.3053 7060080 class_exists ( ) ..\ClassRegistry.php:135
25 0.3053 7060392 App::load( ) ..\ClassRegistry.php:0
Merci pour ton aide !
a priori là, il te dit que tu as une parenthèse en trop ou en moins ligne 24.
Redonne moi ton Post.php
<?php
class Post extends AppModel{
public function afterFind($data){
foreach ($data as $k=>$d) {
foreach($data as $k=>$d){
if(isset($d'Post']'slug']) && isset($d'Post']'id'])){
$d'Post']'link'] = array(
'controller' => 'pages',
'action' => 'show',
'id' => $d'Post']'id'],
'slug' => $d'Post']'slug']
);
}
$data$k] = $d;
}
return $data;
}
}
public function beforeSave(){
debug($this->data);
if(empty($this->data'Post']'slug']) && isset($this->data'Post']'slug']) && !empty($this->data'Post']'name']))
$this->data'post']'slug'] = strtolower(Inflector::slug($this->data'Post']'name'])
));
return true;
}
}
?>
tu as toujours ta parenthèse en trop ligne 23.
c'est de ma faute j'ai laissé ton erreur dans ma réponse d'avant.
J'ai enlever la parenthèse de trop, maintenant j'ai cette érreur:
( ! ) Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\Project\cake_php_blog\app\Model\Post.php on line 23
Call Stack
# Time Memory Function Location
1 0.1749 4583376 ErrorHandler::handleException( ) ..\ErrorHandler.php:0
2 0.1998 4784808 ExceptionRenderer->render( ) ..\ErrorHandler.php:127
3 0.1998 4785512 call_user_func_array ( ) ..\ExceptionRenderer.php:170
4 0.1998 4785544 ExceptionRenderer->_cakeError( ) ..\ExceptionRenderer.php:170
5 0.2001 4786680 ExceptionRenderer->_outputMessage( ) ..\ExceptionRenderer.php:192
6 0.2002 4786680 Controller->render( ) ..\ExceptionRenderer.php:267
7 0.2159 5141256 View->render( ) ..\Controller.php:901
8 0.2719 6930368 View->renderLayout( ) ..\View.php:376
9 0.2733 6931856 View->_render( ) ..\View.php:414
10 0.2745 6985328 include( 'C:\wamp\www\Project\cake_php_blog\app\View\Layouts\default.ctp' ) ..\View.php:598
11 0.2749 6985408 View->element( ) ..\default.ctp:14
12 0.2758 6987160 View->_render( ) ..\View.php:320
13 0.2768 7039600 include( 'C:\wamp\www\Project\cake_php_blog\app\View\Elements\menu.ctp' ) ..\View.php:598
14 0.2768 7040288 Object->requestAction( ) ..\menu.ctp:1
15 0.2785 7045888 Dispatcher->dispatch( ) ..\Object.php:88
16 0.2808 7053016 Dispatcher->_invoke( ) ..\Dispatcher.php:88
17 0.2818 7055296 Controller->invokeAction( ) ..\Dispatcher.php:106
18 0.2819 7056744 ReflectionMethod->invokeArgs( ) ..\Controller.php:476
19 0.2819 7056776 PagesController->menu( ) ..\Controller.php:476
20 0.2820 7056976 Controller->__get( ) ..\Controller.php:10
21 0.2820 7056976 Controller->__isset( ) ..\Controller.php:396
22 0.2820 7057024 Controller->loadModel( ) ..\Controller.php:358
23 0.2821 7057960 ClassRegistry::init( ) ..\Controller.php:673
24 0.2824 7060080 class_exists ( ) ..\ClassRegistry.php:135
25 0.2825 7060392 App::load( ) ..\ClassRegistry.php:0
Mon code :
<?php
class Post extends AppModel{
public function afterFind($data){
foreach ($data as $k=>$d) {
foreach($data as $k=>$d){
if(isset($d'Post']'slug']) && isset($d'Post']'id'])){
$d'Post']'link'] = array(
'controller' => 'pages',
'action' => 'show',
'id' => $d'Post']'id'],
'slug' => $d'Post']'slug']
);
}
$data$k] = $d;
}
return $data;
}
}
public function beforeSave(){
debug($this->data);
if(empty($this->data'Post']'slug']) && isset($this->data'Post']'slug']) && !empty($this->data'Post']'name'])
$this->data'post']'slug'] = strtolower(Inflector::slug($this->data'Post']'name'])
));
return true;
}
}
?>
ça marche :) merci :D
Je lock pas , si j'ai d'autre érreur.
Merci beaucoup zenkiai ! :)