Amis de chez Grafikart bonjour,
Je me retourne déjà vers vous pour un nouveau problème :
J'essaye de migrer mon petit blog de la version 1.3 vers la 2.0 en suivant le tutoriel assimilé.
Tout roule c'est pas trop dur d'autant que j'avais pas grand chose à migrer. Hélas mon Mark it up helper et son bbcode parser que j'avais réussi à faire fonctionner sur 1.3 ne fonctionne plus sur 2.0. quand j'invoque la fonction :
<?php $this->Markitup->editor($mes paramètres) ?>
Je me mange un "Fatal error: Call to a member function editor() on a non-object in" etc ....
J'ai donc tenté dans mon helper de changé certaines lignes conformément au nouveau procédé de la 2.0 mais ça ne marche toujours pas.
<u> Question</u>: Est ce que je peux vous maitre les codes de mon helper en version 1.3 puis celui en version 2.0 que j'ai commencé à modifié pour que vous voyez ce qui ne va pas ce que j'aurai oublié ou mal fait ? :)
Merci d'avance :)
Le code de mon markitup helper en 1.3 nommé markitup.php:
<?php
/**
* markItUp! Helpers
* @author Jay Salvat
* @version 1.0
*
* Download markItUp! at:
* http://markitup.jaysalvat.com
* Download jQuery at:
* http://jquery.com
*/
class MarkitupHelper extends AppHelper {
var $helpers = array('Html', 'Form', 'Javascript');
function fiverEditor($field){
return '
<div class="input text required clearfix">
'. $this->Form->label('Topic.body').'
<div class="textileArea">
'
. $this->editor('body', array("div"=>false,"label"=>false,"set" => "textile")).'
</div>
</div>';
}
/**
* Generates a form textarea element complete with label and wrapper div with markItUp! applied.
* @param string $fieldName This should be "Modelname.fieldname"
* @param array $settings
* @return string An <textarea /> element.
*/
function editor($name, $settings = array()) {
$config = $this->_build($settings);
$settings = $config'settings'];
$default = $config'default'];
$textarea = array_diff_key($settings, $default);
$textarea = am($textarea, array('type' => 'textarea'));
$editor = $this->Form->input($name, $textarea);
$id = '#'.parent::domId($name);
$editor.= $this->Javascript->codeBlock('jQuery.noConflict();jQuery(function() { jQuery("'.$id.'").markItUp('.$settings'settings'].', { previewParserPath:"'.$settings'parser'].'" } ); });');
return $this->output($editor);
}
/**
* Link to build markItUp! on a existing textfield
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param array $settings
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function create($title, $fieldName = "", $settings = array(), $htmlAttributes = array(), $confirmMessage = false) {
$id = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
$config = $this->_build($settings);
$settings = $config'settings'];
$htmlAttributes = am($htmlAttributes, array('onclick' => 'jQuery("'.$id.'").markItUpRemove(); jQuery("'.$id.'").markItUp('.$settings'settings'].', { previewParserPath:"'.$settings'parser'].'" }); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Link to destroy a markItUp! editor from a textfield
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function destroy($title, $fieldName = "", $htmlAttributes = array(), $confirmMessage = false) {
$id = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
$htmlAttributes = am($htmlAttributes, array('onclick' => 'jQuery("'.$id.'").markItUpRemove(); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Link to add content to the focused textarea
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param mixed $content String or array of markItUp! options (openWith, closeWith, replaceWith, placeHolder and more. See markItUp! documentation for more details : http://markitup.jaysalvat.com/documentation
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function insert($title, $fieldName = null, $content = array(), $htmlAttributes = array(), $confirmMessage = false) {
if (isset($fieldName)) {
$content'target'] = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
}
if (!is_array($content)) {
$content'replaceWith'] = $content;
}
$properties = '';
foreach($content as $k => $v) {
$properties .= $k.':"'.addslashes($v).'",';
}
$properties = substr($properties, 0, -1);
$htmlAttributes = am($htmlAttributes, array('onclick' => '$.markItUp( { '.$properties.' } ); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Parser to use in the preview
* @param string $content The content to be parsed.
* @return string Parsed content.
*/
function parse($content, $parser = 'bbcode') {
// This Helper is designed to be used with several kinds of parser
// in a same project.
// Drop your favorite parsers in the /vendor/ folder and edit lines below.
switch($parser) {
case 'bbcode':
App::import('Vendor', 'bbcode', array('file' => 'bbcode'.DS.'markitup.bbcode-parser.php'));
$parsed = BBCode2Html($content);
break;
case 'textile':
//App::import('Vendor','classTextile', array('file'=>'classTextile.php'));
//$psr = new Textile;
//$content = $psr->TextileThis($content);
break;
case 'markdown':
// App::import('Vendor', 'markdown', array('file' => 'myFavoriteMarkDownParser'));
// $parsed = myFavoriteMarkDownParser($content);
break;
default:
// App::import('Vendor', 'favorite', array('file' => 'myFavoriteFavoriteParser'));
// $parsed = myFavoriteFavoriteParser($content);
}
return $parsed;
}
/**
* Adds jQuery and markItUp! scripts to the page
*/
function beforeRender() {
$this->Javascript->link('jquery/jquery.js', false);
$this->Javascript->link('markitup/jquery.markitup.js', false);
}
/**
* Private function.
* Builds the settings array and add includes.
*/
function _build($settings) {
$default = array( 'set' => 'default',
'skin' => 'markitup',
'settings' => 'mySettings',
'parser' => '');
$settings = am($default, $settings);
if ($settings'parser']) {
$settings'parser'] = $this->Html->url($settings'parser']);
}
$this->Javascript->link('markitup/sets/'.$settings'set'].'/set.js', false);
$this->Html->css('/js/markitup/skins/'.$settings'skin'].'/style.css', null,array('inline'=>false));
$this->Html->css('/js/markitup/sets/'.$settings'set'].'/style.css', null,array('inline'=>false));
return array('settings' => $settings, 'default' => $default);
}
}
et le code de mon markitup helper en 2.0 que j'ai commencé à modifié nommé MarkitupHelper.php :
<?php
/**
* markItUp! Helpers
* @author Jay Salvat
* @version 1.0
*
* Download markItUp! at:
* http://markitup.jaysalvat.com
* Download jQuery at:
* http://jquery.com
*/
class MarkitupHelper extends AppHelper {
var $Helpers = array('Html', 'Form', 'script');
function fiverEditor($field){
return '
<div class="input text required clearfix">
'. $this->Html->Form->label('Topic.body').'
<div class="textileArea">
'
. $this->editor('body', array("div"=>false,"label"=>false,"set" => "textile")).'
</div>
</div>';
}
/**
* Generates a form textarea element complete with label and wrapper div with markItUp! applied.
* @param string $fieldName This should be "Modelname.fieldname"
* @param array $settings
* @return string An <textarea /> element.
*/
function editor($name, $settings = array()) {
$config = $this->_build($settings);
$settings = $config'settings'];
$default = $config'default'];
$textarea = array_diff_key($settings, $default);
$textarea = am($textarea, array('type' => 'textarea'));
$editor = $this->Html->Form->input($name, $textarea);
$id = '#'.parent::domId($name);
$editor.= $this->Html->script->codeBlock('jQuery.noConflict();jQuery(function() { jQuery("'.$id.'").markItUp('.$settings'settings'].', { previewParserPath:"'.$settings'parser'].'" } ); });');
return $this->output($editor);
}
/**
* Link to build markItUp! on a existing textfield
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param array $settings
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function create($title, $fieldName = "", $settings = array(), $htmlAttributes = array(), $confirmMessage = false) {
$id = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
$config = $this->_build($settings);
$settings = $config'settings'];
$htmlAttributes = am($htmlAttributes, array('onclick' => 'jQuery("'.$id.'").markItUpRemove(); jQuery("'.$id.'").markItUp('.$settings'settings'].', { previewParserPath:"'.$settings'parser'].'" }); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Link to destroy a markItUp! editor from a textfield
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function destroy($title, $fieldName = "", $htmlAttributes = array(), $confirmMessage = false) {
$id = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
$htmlAttributes = am($htmlAttributes, array('onclick' => 'jQuery("'.$id.'").markItUpRemove(); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Link to add content to the focused textarea
* @param string $title The content to be wrapped by <a> tags.
* @param string $fieldName This should be "Modelname.fieldname" or specific domId as #id.
* @param mixed $content String or array of markItUp! options (openWith, closeWith, replaceWith, placeHolder and more. See markItUp! documentation for more details : http://markitup.jaysalvat.com/documentation
* @param array $htmlAttributes Array of HTML attributes.
* @param string $confirmMessage JavaScript confirmation message.
* @return string An <a /> element.
*/
function insert($title, $fieldName = null, $content = array(), $htmlAttributes = array(), $confirmMessage = false) {
if (isset($fieldName)) {
$content'target'] = ($fieldName{0} === '#') ? $fieldName : '#'.parent::domId($fieldName);
}
if (!is_array($content)) {
$content'replaceWith'] = $content;
}
$properties = '';
foreach($content as $k => $v) {
$properties .= $k.':"'.addslashes($v).'",';
}
$properties = substr($properties, 0, -1);
$htmlAttributes = am($htmlAttributes, array('onclick' => '$.markItUp( { '.$properties.' } ); return false;'));
return $this->Html->link($title, "#", $htmlAttributes, $confirmMessage, false);
}
/**
* Parser to use in the preview
* @param string $content The content to be parsed.
* @return string Parsed content.
*/
function parse($content, $parser = 'bbcode') {
// This Helper is designed to be used with several kinds of parser
// in a same project.
// Drop your favorite parsers in the /vendor/ folder and edit lines below.
switch($parser) {
case 'bbcode':
App::import('Vendor', 'bbcode', array('file' => 'bbcode'.DS.'markitup.bbcode-parser.php'));
$parsed = BBCode2Html($content);
break;
case 'textile':
//App::import('Vendor','classTextile', array('file'=>'classTextile.php'));
//$psr = new Textile;
//$content = $psr->TextileThis($content);
break;
case 'markdown':
// App::import('Vendor', 'markdown', array('file' => 'myFavoriteMarkDownParser'));
// $parsed = myFavoriteMarkDownParser($content);
break;
default:
// App::import('Vendor', 'favorite', array('file' => 'myFavoriteFavoriteParser'));
// $parsed = myFavoriteFavoriteParser($content);
}
return $parsed;
}
/**
* Adds jQuery and markItUp! scripts to the page
*/
function beforeRender() {
$this->Html->script->link('jquery/jquery.js', false);
$this->Html->script->link('markitup/jquery.markitup.js', false);
}
/**
* Private function.
* Builds the settings array and add includes.
*/
function _build($settings) {
$default = array( 'set' => 'default',
'skin' => 'markitup',
'settings' => 'mySettings',
'parser' => '');
$settings = am($default, $settings);
if ($settings'parser']) {
$settings'parser'] = $this->Html->url($settings'parser']);
}
$this->Html->script->link('markitup/sets/'.$settings'set'].'/set.js', false);
$this->Html->css('/js/markitup/skins/'.$settings'skin'].'/style.css', null,array('inline'=>false));
$this->Html->css('/js/markitup/sets/'.$settings'set'].'/style.css', null,array('inline'=>false));
return array('settings' => $settings, 'default' => $default);
}
}
Merci :)
salut,
Je ne sais pas si tu as modifié depuis mais j'ai vu que tu as var $helpers = array()
A la place de var, dans la nouvelle version de cake, il faut mettre public
ah bon ? pourtant dans sa vidéo il parle pas de ça, bon j'ai quand même fait la modif pour voir mais ça change pas le message.
Merci quand même :)
Je me demande de plus en plus si le problème vient du helper et pas d'un problème de dossier ou de nomenclature de fichier car mon erreur dit qu'il trouve pas le fonction pas que la fonction est bugué ...
Un autre petit, j'ai comparé avec ce qu'il met
Tu as $This->Html->script->link()
et si tu mets
$This->Html->script()
apparemment il n'y a pas besoin du link
Pour les nomenclatures
Dans controller, exemple:
PostsController.php
<?php
class PostsController extends AppController{} ?>
MAintenant le appconntroller, on le met dans le dossier controller
AppController.php
<?php
class AppController extends Controller{} ?>
Dans les models, la 1ère lettre est en majuscule au lieu de minuscule
Dans View, idem que models et le fichier toujours au pluriel
Sinon, tu regardes les vidéos qu'il a fait avec cakephp 2.0, il parle des changements au fur et à mesure
faudrait mettre public function non aussi au lieu de function tout seul quand pensez vous ?
Personne n'a donc une idée du fait que je me tape un "Fatal error: Call to a member function editor() on a non-object in etc .." depuis que j'ai passé mon blog en 2.0 quand j'invoque dans une de mes vues la méthode $this->Markitupe->edit()?
Cette erreur dit bien que PhP ne trouve pas la classe associé à la méthode $this->Markitup->edit() non ?