Add class to this line... php/css - php

I have this line in php
<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.$LinkClass.'>
I need to add another class which is known called tip
The code above generates something like this:
<a class="ProfileLink" href="/respond/profile/2/422" title="422">
As you can see $LinkClass gives me the class "ProfileLink" which is great
But I need to parse the class like "ProfileLink tip"
So just not sure how to amend $LinkClass above to something like $LinkClass tip
This is probably so basic I just cant see the wood for the trees
//
Edit: to add
Final html output needs to be :
<a class="ProfileLink tip" href="/respond/profile/2/422" title="422">
//
Added:
Entire php output for this function is:
if (!function_exists('UserPhoto')) {
function UserPhoto($User, $Options = array()) {
$User = (object)$User;
if (is_string($Options))
$Options = array('LinkClass' => $Options);
$LinkClass = GetValue('LinkClass', $Options, 'ProfileLink');
$ImgClass = GetValue('ImageClass', $Options, 'ProfilePhotoMedium');
$LinkClass = $LinkClass == '' ? '' : ' class="'.$LinkClass.'"';
$Photo = $User->Photo;
if (!$Photo && function_exists('UserPhotoDefaultUrl'))
$Photo = UserPhotoDefaultUrl($User);
if ($Photo) {
if (!preg_match('`^https?://`i', $Photo)) {
$PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
} else {
$PhotoUrl = $Photo;
}
$Href = Url(UserUrl($User));
return '<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.$LinkClass.'>'
.Img($PhotoUrl, array('alt' => htmlspecialchars($User->Name), 'class' => $ImgClass))
.'</a>';
} else {
return '';
}
}
}

How about using an array for the class attribute? Like this:
$LinkClass= array();
$LinkClassVal = GetValue('LinkClass', $Options, 'ProfileLink');
if($LinkClassVal){
$LinkClass[] = $LinkClassVal;
}
$LinkClass[] = "tip";
and then on return :
return '<a title="'.htmlspecialchars($User->Name).'" href="'.$Href.'"'.implode(" ",$LinkClass).'>'
.Img($PhotoUrl, array('alt' => htmlspecialchars($User->Name), 'class' => $ImgClass))
.'</a>';

Related

Shortcode with array of options and conditional display based on options

I have been looking for a solution and couldn't find.
I have created a shortcode that displays social link depends on type with folowing code:
function ns_social_buttons_dynamic($atts,$content,$tag) {
$facebookUrl = get_option('ns-company-facebook');
$messengerUrl = get_option('ns-company-messenger');
if (!empty($facebookUrl)) {
$fb = '<a class="btn-ns btn-ns-second m-1 bg-facebook" href="https://facebook.com/'.$facebookUrl.'" role="button" target="blank"><i class="fab fa-facebook-f"></i></a>';
};
if (!empty($messengerUrl)) {
$msngr = '<a class="btn-ns btn-ns-second m-1 bg-messenger" href="https://m.me/'.$messengerUrl.'" role="button" target="blank"><i class="fab fa-facebook-messenger"></i></a>';
}
$nsSocial = $fb . $msngr;
//get admin url
$addLink = get_site_url( $blog_id, 'wp-admin/', $scheme );
//default value of shortcodes shows all social buttons
$values = shortcode_atts(array(
'type' => 'all',
'output' => 'raw',
),$atts);
//social button based on type
$output = '';
if($values['type'] == 'all' and !empty($nsSocial)){
$output = $nsSocial;
}
else if($values['type'] == 'facebook' and !empty($facebookUrl)){
$output = $fb;
}
else if($values['type'] == 'messenger' and !empty($messengerUrl)){
$output = $msngr;
}
else {
$output = 'field is empty <a href=' . $addLink . 'admin.php?page=ns-settings' .' >add username</a>';
}
return $output;
}
add_shortcode( 'ns-social', 'ns_social_buttons_dynamic' );
This code works just fine e.g [ns-socia type='facebook'] will output the right button.
now what I need is if the shortcode like following [ns-socia type='facebook' output='raw'] to show only the url and not the button.
I tried following:
//social button based on type
$output = '';
if($values['type'] == 'all' and !empty($nsSocial)){
$output = $nsSocial;
}
else if($values['type'] == 'facebook' and $values['output'] == 'raw' and !empty($facebookUrl)){
$output = $facebookUrl;
}
else if($values['type'] == 'messenger' and $values['output'] == 'raw' and !empty($messengerUrl)){
$output = $messengerUrl;
}
else {
$output = 'field is empty <a href=' . $addLink . 'admin.php?page=ns-settings' .' >add username</a>';
}
return $output;
I am not sure i am doing it right with the conditional php conditional statements...

Add target _blank to external link - Parsedown PHP

I'm using Parsedown to parse HTML from the database to my site. With Parsedown, you can't really add target="_blank" to the links.
So what I'm trying to do is to add target="_blank" to external links. I've found this function in Parsedown.php:
protected function inlineLink($Excerpt)
{
$Element = array(
'name' => 'a',
'handler' => 'line',
'text' => null,
'attributes' => array(
'href' => null,
'title' => null,
),
);
$extent = 0;
$remainder = $Excerpt['text'];
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches))
{
$Element['text'] = $matches[1];
$extent += strlen($matches[0]);
$remainder = substr($remainder, $extent);
}
else
{
return;
}
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches))
{
$Element['attributes']['href'] = $matches[1];
if (isset($matches[2]))
{
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
}
$extent += strlen($matches[0]);
}
else
{
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
{
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);
$extent += strlen($matches[0]);
}
else
{
$definition = strtolower($Element['text']);
}
if ( ! isset($this->DefinitionData['Reference'][$definition]))
{
return;
}
$Definition = $this->DefinitionData['Reference'][$definition];
$Element['attributes']['href'] = $Definition['url'];
$Element['attributes']['title'] = $Definition['title'];
}
$Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']);
return array(
'extent' => $extent,
'element' => $Element,
);
}
Now, what I've tried is this (added a comment of what I changed):
protected function inlineLink($Excerpt)
{
$Element = array(
'name' => 'a',
'handler' => 'line',
'text' => null,
'attributes' => array(
'href' => null,
'target' => null, // added this
'title' => null,
),
);
$extent = 0;
$remainder = $Excerpt['text'];
if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches))
{
$Element['text'] = $matches[1];
$extent += strlen($matches[0]);
$remainder = substr($remainder, $extent);
}
else
{
return;
}
if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches))
{
$Element['attributes']['href'] = $matches[1];
if (isset($matches[2]))
{
$Element['attributes']['title'] = substr($matches[2], 1, - 1);
}
$extent += strlen($matches[0]);
}
else
{
if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
{
$definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
$definition = strtolower($definition);
$extent += strlen($matches[0]);
}
else
{
$definition = strtolower($Element['text']);
}
if ( ! isset($this->DefinitionData['Reference'][$definition]))
{
return;
}
$Definition = $this->DefinitionData['Reference'][$definition];
$Element['attributes']['href'] = $Definition['url'];
if (strpos($Definition['url'], 'example.com') !== false) { // added this aswell, checking if its our own URL
$Element['attributes']['target'] = '_blank';
}
$Element['attributes']['title'] = $Definition['title'];
}
$Element['attributes']['href'] = str_replace(array('&', '<'), array('&', '<'), $Element['attributes']['href']);
return array(
'extent' => $extent,
'element' => $Element,
);
}
Any suggestions to accomplish this?
Ran into this issue today. I wanted to have all links from a different host open up in a new target automatically. Unfortunately, the accepted answer recommends editing the Parsedown class file, which is a bad idea imo.
I created a new PHP class which extends Parsedown, and created an override for the element method. Here is the whole class:
class ParsedownExtended extends Parsedown
{
protected function element(array $Element)
{
if ($this->safeMode) {
$Element = $this->sanitiseElement($Element);
}
$markup = '<' . $Element['name'];
if (isset($Element['name']) && $Element['name'] == 'a') {
$server_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
$href_host = isset($Element['attributes']['href']) ? parse_url($Element['attributes']['href'], PHP_URL_HOST) : null;
if ($server_host != $href_host) {
$Element['attributes']['target'] = '_blank';
}
}
if (isset($Element['attributes'])) {
foreach ($Element['attributes'] as $name => $value) {
if ($value === null) {
continue;
}
$markup .= ' ' . $name . '="' . self::escape($value) . '"';
}
}
if (isset($Element['text'])) {
$markup .= '>';
if (!isset($Element['nonNestables'])) {
$Element['nonNestables'] = array();
}
if (isset($Element['handler'])) {
$markup .= $this->{$Element['handler']}($Element['text'], $Element['nonNestables']);
}
else {
$markup .= self::escape($Element['text'], true);
}
$markup .= '</' . $Element['name'] . '>';
}
else {
$markup .= ' />';
}
return $markup;
}
}
Here is where the magic happens:
if (isset($Element['name']) && $Element['name'] == 'a') {
$server_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
$href_host = isset($Element['attributes']['href']) ? parse_url($Element['attributes']['href'], PHP_URL_HOST) : null;
if ($server_host != $href_host) {
$Element['attributes']['target'] = '_blank';
}
}
Now I simply use ParsedownExtended instead of Parsedown when parsing content, e.g.:
$parsedown = new ParsedownExtended();
return $parsedown->text($this->body);
Hope this helps someone.
Such issue already exists on GitHub. Please see this comment.
My extension can automatically set rel="nofollow" and target="_blank"
attributes to a link when it is detected as an external link. You can
also set those attributes manually through the attribute block:
[text](http://example.com) {rel="nofollow" target="_blank"}
Automatic rel="nofollow" Attribute on External Links
// custom external link attributes
$parser->links_external_attr = array(
'rel' => 'nofollow',
'target' => '_blank'
);
If you want to make changes in Parsedown class without using the parsedown-extra-plugin extension, you can do as follows:
1) In \Parsedown::element method after the first line $markup = '<'.$Element['name']; add this line $Element = $this->additionalProcessElement($Element);
2) Add new method to Parsedown class:
protected function additionalProcessElement($Element) { }
3) Extend Parsedown class and save it as MyParsedown.php file:
<?php
namespace myapps;
require_once __DIR__.'/Parsedown.php';
/**
* Class MyParsedown
* #package app
*/
class MyParsedown extends \Parsedown
{
/**
* #param array $Element
* #return array
*/
protected function additionalProcessElement($Element)
{
if ($Element['name'] == 'a' && $this->isExternalUrl($Element['attributes']['href'])) {
$Element['attributes']['target'] = '_blank';
}
return $Element;
}
/**
* Modification of the funciton from answer to the question "How To Check Whether A URL Is External URL or Internal URL With PHP?"
* #param string $url
* #param null $internalHostName
* #see https://stackoverflow.com/a/22964930/7663972
* #return bool
*/
protected function isExternalUrl($url, $internalHostName = null) {
$components = parse_url($url);
$internalHostName = ($internalHostName == null) ? $_SERVER['HTTP_HOST'] : $internalHostName;
// we will treat url like '/relative.php' as relative
if (empty($components['host'])) {
return false;
}
// url host looks exactly like the local host
if (strcasecmp($components['host'], $internalHostName) === 0) {
return false;
}
$isNotSubdomain = strrpos(strtolower($components['host']), '.'.$internalHostName) !== strlen($components['host']) - strlen('.'.$internalHostName);
return $isNotSubdomain;
}
}
4) Create test.php file and run it:
require_once __DIR__.'/MyParsedown.php';
$parsedown = new \myapps\MyParsedown();
$text = 'External link to [example.com](http://example.com/abc)';
echo $parsedown->text($text);
This HTML code will be displayed on the browser page (if your host is not example.com, of course):
<p>External link to example.com</p>
Just like kjdion84 I'd also extend the Parsedown class. I suggest to not copy and change the element method but overwrite inlineLink; it's less work and more future proof if the base code changes.
Heads up: the urlIsExternal method is by no means complete (host check is missing).
class ParsedownExtended extends Parsedown
{
protected function inlineLink($Excerpt)
{
$link = parent::inlineLink($Excerpt);
if ($this->urlIsExternal($link['element']['attributes']['href'])) {
$link['element']['attributes'] += [
'target' => '_blank',
'rel' => 'nofollow',
];
}
return $link;
}
protected function urlIsExternal($url)
{
$scheme = parse_url($url, PHP_URL_SCHEME);
$host = parse_url($url, PHP_URL_HOST);
if (!$scheme || !$host) {
return false;
}
if (strpos(strtolower($scheme), 'http') !== 0) {
return false;
}
// #TODO check the host
return true;
}
}
This will work.
<?php
declare(strict_types=1);
namespace YourNamespace;
class ParsedownExt extends \Parsedown
{
// Add target to links
protected function element(array $Element)
{
if (strcasecmp($Element['name'], 'a')===0)
$Element['attributes']['target'] = '_blank';
return parent::element($Element);
}
}

Multilevel submenu codeigniter

I have to extend an existing menu to a multilevel one. I am having a hard time wrapping my head around it so I'm hoping somebody can help me out.
First I've added another table in the database with the name parent_id.
Then I'd like to see if this column is filled out, so greater than > 0.
And then of course, check to see if id == parent_id.
If so, I'd like to display my submenu on hover of the parent item.
My current menu is a multi lang menu.
This is my current model:
var $default_order_by = array('position');
function findView($page)
{
$language = $this->config->item('language');
$p = new Page();
$p->where('url_' . $language, $page)->get();
return $p->view;
}
function findPageMenu($page)
{
$language = $this->config->item('language');
$p = new Page();
$p->where('url_' . $language, $page)->get();
return $p->menu;
}
function findAllByView()
{
$pages = new Page();
$result = array();
foreach ($pages->get() as $page)
$result[$page->view] = $page;
return $result;
}
function getMenu()
{
$pages = new Page();
if ($this->session->userdata('is_admin'))
return $pages->where('position >', 0)->get();
else
return $pages->where('position >', 0)->where('admin', 0)->get();
}
function getUrlByView($view)
{
$page = new Page();
$page->where('view', $view)->get();
$language = $this->config->item('language');
return $page->{'url_' . $language};
}
And this is my view:
<ul class="primary-nav">
<?php foreach($menu as $page): ?>
<li class="primary-nav__item">
<a class="primary-nav__link" <?php if ($page_menu == $page->view): ?>class="active" <?php endif; ?>href="<?php echo base_url() . $this->config->item('language_abbr') . '/' . $page->{'url_' . $this->config->item('language')}; ?>">
<?php echo mb_strtoupper($page->{'title_' . $this->config->item('language')}, 'UTF-8'); ?>
</a>
</li>
<?php endforeach; ?>
I was thinking of doing something like this:
function getSubMenu()
{
if ($this->session->userdata('is_admin'))
return $pages->where('position >', 0 && 'parent_id >', 0)->get();
else
// return $pages->where('position >', 0 && 'parent_id >', 0)->get();
echo '<h1> yay </h1>';
}
(ignore the yay, lol) But this obviously doesn't even begin to cut it.
Suggestion: You can add the "parent_id" in the same table. If there is a parent then fill it with parent id or with 0.
Answer: Get your data as a one dimentional array with all the rows with parent id. Then use the below function to create a multi dimensional array with parent and child.
function formatTree($tree, $parent = NULL) {
$treeArray = array();
foreach ($tree as $item) {
if ($item['menu_parent'] == 0) {
$treeArray[$item['menu_id']] = $item;
}
else {
$treeArray[$item['menu_parent']]['sub'][] = $item;
}
}
return $treeArray;
}
Now use the below function to make an intended ul-li list of parent-child menu
function buildMenu($menu_array, $is_sub = FALSE) {
$attr = (!$is_sub) ? ' class="sidebar-menu"' : ' class="treeview-menu"';
$menu = "<ul>"; // Open the menu container
foreach ($menu_array as $id => $properties) {
if (!isset($properties['sub'])) {
$is_sub = TRUE;
}
elseif (empty($properties['sub'])) {
$is_sub = TRUE;
}
foreach ($properties as $key => $val) {
if (is_array($val) && !empty($val)) {
$sub = $this -> buildMenu($val, TRUE);
}
else {
$sub = NULL;
$$key = $val;
}
}
if ($properties['menu_url']) {
$url = $properties['menu_url'];
}
$menu .= "<li>" . $menu_name . "</li>";
unset($url, $menu_name, $sub);
}
return $menu . "</ul>";
}
I am using this in my application. The array structure of menu data should be
array(
[0] => array(
'menu_name' => 'name',
'menu_url' => 'url',
'menu_id' => 'id',
'menu_parent' => 'parent id'
),
[1] => array(
'menu_name' => 'name',
'menu_url' => 'url',
'menu_id' => 'id',
'menu_parent' => 'parent id'
)
)

CakePHP Paginator Table Header Directional Icons

I'm trying to implement a function to be able to add directional (up / down) icons next to each of the table headers for a pagination table within CakePHP.
My current code is as follows:
$sort_key = $this->Paginator->sortKey();
$type = $this->Paginator->sortDir() === 'asc' ? 'up' : 'down';
function sortArrows($key, $title, $sort_key, $type)
{
$type_opposite = ($type === 'asc' ? 'down' : 'up');
if($key == $sort_key)
{
$icon = " <i class='fa fa-angle-" . $type . "'></i>";
}
else
{
$icon = " <i class='fa fa-angle-" . $type_opposite . "'></i>";
}
return "'$key', '$title' " . "$icon";
}
Which I am calling on the page as (on each of the table header fields):
<?php echo $this->Paginator->sort(sortArrows('street_suburb', 'Suburb', $sort_key, $type), array('escape' => false)); ?>
This produces the following error:
Notice (8): Array to string conversion [CORE/Cake/View/Helper/HtmlHelper.php, line 372]
I think I am quite close to what I need, I just cannot figure out what I am returning incorrectly from the function to get this to work.
Thanks
Inspired by your solution I have created a Helper extending PaginatorHelper to solve the problem.
Here is the code of file name MyPaginatorHelper.php:
<?php
namespace App\View\Helper;
use Cake\View\Helper\PaginatorHelper;
use Cake\Utility\Inflector;
class MyPaginatorHelper extends PaginatorHelper
{
public function sort($key, $title = null, array $options = [])
{
if (empty($title)) {
$title = $key;
if (strpos($title, '.') !== false) {
$title = str_replace('.', ' ', $title);
}
$title = __(Inflector::humanize(preg_replace('/_id$/', '', $title)));
}
$sortKey = $this->sortKey();
if (strpos($sortKey, '.') !== false) {
$sortKey = substr($sortKey, strpos($sortKey, '.')+1);
}
$sortDir = $this->sortDir() === 'asc' ? 'up' : 'down';
if($key == $sortKey)
{
$title .= " <i class='fa fa-angle-" . $sortDir . "'></i>";
$options['escape'] = false;
}
return parent::sort($key, $title, $options);
}
}
To use this helper you have to add this line in the AppView::initialize() method:
$this->loadHelper('Paginator', ['className' => 'MyPaginator']);
And then all the Paginator->sort() calls will have this feature by default.
I ended up coming up with a solution however I don't know if it is the best way around it. It does work however.
<?php
$sort_key = $this->Paginator->sortKey();
$type = $this->Paginator->sortDir() === 'asc' ? 'up' : 'down';
function sortArrows($key, $title, $sort_key, $type)
{
if($key == $sort_key)
{
$icon = " <i class='fa fa-angle-" . $type . "'></i>";
return $title . " " . $icon;
}
else
{
return $title;
}
}
?>
Called like:
<?php echo $this->Paginator->sort('street_suburb', sortArrows('street_suburb', 'Suburb', $sort_key, $type), array('escape' => false)); ?>

T_PAAMAYIM_NEKUDOTAYIM Error after override CButtonColumn

I overrode CButtonColumn class and code worked in perfect way on localhost(windows) , but when I uploaded it to linux server I had this error :
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in /home/xxx/public_html/protected/components/GridView/XCButtonColumn.php on line 65
I read about what mean "T_PAAMAYIM_NEKUDOTAYIM" , it's mean "::"
link here
,but I didn't understood what i can do to fix problem .
line 65:
if (is_array($modelClass::model()->primaryKey))
This is my code :
<?php
class XCButtonColumn extends CButtonColumn
{
public $htmlOptions = array('class' => 'center vcenter');
public $viewButtonOptions = array('class' => 'btn btn-default tip view');
public $viewButtonImageUrl = '';
public $viewButtonHtml;
public $updateButtonOptions = array('class' => 'btn btn-default tip update');
public $updateButtonImageUrl = '';
public $updateButtonHtml;
public $deleteButtonOptions = array('class' => 'btn btn-default tip delete');
public $deleteButtonImageUrl = '';
public $deleteButtonHtml;
public $showImage = false;
public $showHtml = true;
protected function renderButton($id, $button, $row, $data)
{
if (isset($button['visible']) && !$this->evaluateExpression($button['visible'], array('row' => $row, 'data' => $data))) return;
$label = isset($button['label']) ? $button['label'] : $id;
$url = isset($button['url']) ? $this->evaluateExpression($button['url'], array('data' => $data, 'row' => $row)) : '#';
$options = isset($button['options']) ? $button['options'] : array();
if (!isset($options['title'])) $options['title'] = $label;
if ($this->showImage) {
if (isset($button['imageUrl']) && is_string($button['imageUrl'])) {
echo CHtml::link(CHtml::image($button['imageUrl'], $label), $url, $options);
} else {
echo CHtml::link($label, $url, $options);
}
} else {
if (isset($button['html']) && is_string($button['html'])) {
echo CHtml::link($button['html'], $url, $options);
} else {
echo CHtml::link($button['html'], $url, $options);
}
}
}
protected function initDefaultButtons()
{
if ($this->viewButtonLabel === null) $this->viewButtonLabel = Yii::t('zii', 'View');
if ($this->updateButtonLabel === null)
$this->updateButtonLabel = Yii::t('zii', 'Update');
if ($this->deleteButtonLabel === null)
$this->deleteButtonLabel = Yii::t('zii', 'Delete');
if ($this->viewButtonImageUrl === null)
$this->viewButtonImageUrl = $this->grid->baseScriptUrl .
'/view.png';
if ($this->updateButtonImageUrl === null)
$this->updateButtonImageUrl = $this->grid->baseScriptUrl
. '/update.png';
if ($this->deleteButtonImageUrl === null)
$this->deleteButtonImageUrl = $this->grid->baseScriptUrl
. '/delete.png';
if ($this->viewButtonHtml === null)
$this->viewButtonHtml = '<i class="icon-zoom-in iconwhite"></i>';
if ($this->updateButtonHtml === null)
$this->updateButtonHtml = '<i class="icon-edit iconwhite"></i>';
if ($this->deleteButtonHtml === null)
$this->deleteButtonHtml = '<i class="icon-trash iconwhite"></i>';
if ($this->deleteConfirmation === null)
$this->deleteConfirmation = Yii::t('zii', 'Are you sure you want to delete this item?');
$modelClass = $this->grid->dataProvider->modelClass;
$controller = strtolower($modelClass);
if (is_array($modelClass::model()->primaryKey))
$paramExpression = '",$data->primaryKey)';
else
$paramExpression = '",array("id"=>$data->primaryKey))';
foreach (array('view', 'update', 'delete') as $id) {
$button = array(
'label' => $this->{$id . 'ButtonLabel'},
'url' => 'Yii::app()->urlManager->createUrl("' . "$controller/$id$paramExpression",
'imageUrl' => $this->{$id . 'ButtonImageUrl'},
'html' => $this->{$id . 'ButtonHtml'},
'options' => $this->{$id . 'ButtonOptions'},
);
if (isset($this->buttons[$id]))
$this->buttons[$id] = array_merge($button, $this->buttons[$id]);
else
$this->buttons[$id] = $button;
}
if (!isset($this->buttons['delete']['click'])) {
if (is_string($this->deleteConfirmation))
$confirmation = "if(!confirm(" .
CJavaScript::encode($this->deleteConfirmation) . ")) return false;";
else
$confirmation = '';
if (Yii::app()->request->enableCsrfValidation) {
$csrfTokenName = Yii::app()->request->csrfTokenName;
$csrfToken = Yii::app()->request->csrfToken;
$csrf = "\n\t\tdata:{ '$csrfTokenName':'$csrfToken'
},";
} else
$csrf = '';
if ($this->afterDelete === null)
$this->afterDelete = 'function(){}';
$this->buttons['delete']['click'] = <<<EOD
function() {
$confirmation
var th = this,
afterDelete = $this->afterDelete;
jQuery('#{$this->grid->id}').yiiGridView('update', {
type: 'POST',
url: jQuery(this).attr('href'),$csrf
success: function(data) {
jQuery('#{$this->grid->id}').yiiGridView('update');
afterDelete(th, true, data);
},
error: function(XHR) {
return afterDelete(th, false, XHR);
}
});
return false;
}
EOD;
}
}
}
Thanks in advance
First thanks to benka to help , the problem is in php version and php 5.2 not support
this line :
if (is_array($modelClass::model()->primaryKey))
So to be work on php 5.2 I changed it to be :
if (is_array(CActiveRecord::model($modelClass)->primaryKey))
References :
Link 1
Link 2
should be -> instead of ::
if (is_array($modelClass->model()->primaryKey))

Categories