在我的 MVC 中,它不会跳转到控制器的保存功能中???我试着做一些 die(); 出口点,但这无济于事。主要问题是保存功能。但是删除也不起作用。
这是控制器。
<?php
//*********************************
// Controller
//*********************************
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class FindmeControllerStylelink extends JController
{
function __construct()
{
parent::__construct();
echo '<br>Controller: FindmeControllerStylelink';
}
function display()
{
JRequest::setVar('view', 'stylelink');
parent::display();
}
function edit()
{
JRequest::setVar( 'view', 'stylelink' );
JRequest::setVar( 'layout', 'form' );
parent::display();
}
function add(){
JRequest::setVar( 'view', 'stylelink' );
JRequest::setVar( 'layout', 'form' );
parent::display();
}
function delete(){
$id = JRequest::getVar( 'id' );
$model = $this->getModel('stylelink');
if ($model->delete()) {
$msg = JText::_( 'Data Deleted!' );
} else {
$msg = JText::_( 'Error Deleting Data' );
}
echo 'delete ';
die();
// Check the table in so it can be edited.... we are done with it anyway
$link = 'index.php?option=com_findme&controller=stylelinks';
$this->setRedirect($link, $msg);
}
function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
$post = JRequest::get('post');
print_r($post);
echo 'save ';
die();
$model = $this->getModel('stylelink');
if ($model->store($post)) {
$msg = JText::_( 'Stylelink Saved' );
} else {
$msg = JText::_( 'Error Saving Stylelink' );
}
$link = 'index.php?option=com_findme&controller=stylelinks';
$this->setRedirect($link, $msg);
}
function cancel()
{
// Check for request forgeries
JRequest::checkToken() or jexit( 'Invalid Token' );
echo 'save ';
die();
$link = 'index.php?option=com_findme&controller=stylelinks';
$this->setRedirect($link, $msg);
}
}
?>
风景。
<?php
//*********************************
// insurances View
//*********************************
defined('_JEXEC') or die( 'Restricted Access' );
jimport( 'joomla.application.component.view' );
class FindmeViewStylelink extends JView {
function display($tpl = null) {
global $mainframe, $option, $view;
echo '<br>View: FindmeViewStylelink';
//$model =& $this->getModel();
//$model = &$this->getModel( 'stylelink' );
//var_dump($model);
$db =& JFactory::getDBO();
$uri =& JFactory::getURI();
$view = JRequest::getWord( 'controller' );
//echo '<br>controller '.$view;
//echo '<br>option '.$option;
// Get data from the model
$item = & $this->get( 'Data');
print_r($item);
$this->assignRef('user',JFactory::getUser());
$this->assignRef('item',$item);
// //new Method
// $this->assignRef('user',JFactory::getUser());
// $this->assignRef('items',$model->_log_items);
// $this->assignRef('lists',$model->_log_lists);
// $this->assignRef('pagination',$model->_log_pagination);
parent::display($tpl);
}
}
?>
这是表格。
<?php
//*********************************
// Stylelink
//*********************************
ini_set('display_errors','on');
error_reporting(E_ALL);
JHTML::stylesheet('findme.css', 'components/com_findme/css/');
defined('_JEXEC') or die('Restricted access');
$viewname = 'stylelink';
JHTML::_('behavior.tooltip');
require_once(JPATH_SITE.DS.'components/com_findme/includes/functions.php');
// Set toolbar items for the page
$edit = JRequest::getVar('edit',true);
JToolBarHelper::title('Style Link' );
JToolBarHelper::save();
if (!$edit) {
JToolBarHelper::cancel();
} else {
// for existing items the button is renamed `close`
JToolBarHelper::cancel( 'cancel', 'Close' );
}
echo '<h1>Stylelink Verwaltung </h1>';
?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}
// do field validation
if (form.cat_id.value == ""){
alert( "<?php echo JText::_( 'You must select a category', true ); ?>" );
} else if (form.url_link.value == ""){
alert( "<?php echo JText::_( 'You must have a url.', true ); ?>" );
} else {
submitform( pressbutton );
}
}
</script>
<form action="index.php" method="post" name="adminForm" id="adminForm">
<div class="col width-50">
<fieldset class="adminform">
<legend><?php echo JText::_( 'Details' ); ?></legend>
<table class="admintable">
<tr>
<td width="100" align="right" class="key">
<label for="title">
<?php echo JText::_( 'ID' ); ?>:
</label>
</td>
<td>
<?php echo $this->item->id;?>
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="title">
<?php echo JText::_( 'Name' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="title" id="title" size="100"
maxlength="250" value="<?php echo $this->item->name;?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="cat_id">
<?php echo JText::_( 'cat_id' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="cat_id" id="cat_id" size="10"
maxlength="10" value="<?php echo $this->item->cat_id;?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="language">
<?php echo JText::_( 'language' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="language" id="language" size="10"
maxlength="10" value="<?php echo $this->item->language;?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="active">
<?php echo JText::_( 'active' ); ?>:
</label>
</td>
<td>
<input class="text_area" type="text" name="active" id="active" size="2"
maxlength="2" value="<?php echo $this->item->active;?>" />
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="url_link">
<?php echo JText::_( 'url_link' ); ?>:
</label>
</td>
<td>
<textarea class="text_area" cols="60" rows="4" name="url_link"
id="url_link"><?php echo $this->item->url_link; ?></textarea>
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="url_img_small">
<?php echo JText::_( 'url_img_small' ); ?>:
</label>
</td>
<td>
<textarea class="text_area" cols="60" rows="4" name="url_img_small"
id="url_img_small"><?php echo $this->item->url_img_small; ?></textarea>
</td>
</tr>
<tr>
<td width="100" align="right" class="key">
<label for="url_img_big">
<?php echo JText::_( 'url_img_big' ); ?>:
</label>
</td>
<td>
<textarea class="text_area" cols="60" rows="4" name="url_img_big"
id="url_img_big"><?php echo $this->item->url_img_big; ?></textarea>
</td>
</tr>
</table>
</fieldset>
</div>
<div class="clr"></div>
<input type="hidden" name="option" value="com_findme" />
<input type="hidden" name="id" value="<?php echo $this->item->id; ?>" />
<input type="hidden" name="controller" value="stylelinks" />
<input type="hidden" name="task" value="" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
?>
这是模型
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
class FindmeModelStylelink extends JModel
{
var $_id = null;
var $_data = null;
function __construct()
{
parent::__construct();
echo '<br>FindmeModelStylelink ';
$id = JRequest::getVar('id', 0);
$edit = JRequest::getVar('edit',true);
if($edit)
$this->setId((int)$id);
}
function setId($id)
{
echo '<br/>id ',$id;
// Set id and wipe data
$this->_id = $id;
$this->_data = null;
}
function &getData()
{
// Load the data
if ($this->_loadData())
{
// Initialize some variables
$user = &JFactory::getUser();
}
else $this->_initData();
return $this->_data;
}
function store($data)
{
$row =& $this->getTable();
echo '<br/> store';
// Bind the form fields to the style link table
if (!$row->bind($data)) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Create the timestamp for the date
$row->timestamp = gmdate('Y-m-d H:i:s');
// if new item, order last in appropriate group
//if (!$row->id) {
// $where = 'catid = ' . (int) $row->catid ;
// $row->ordering = $row->getNextOrder( $where );
//}
// Make sure the link table is valid
if (!$row->check()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the link table to the database
if (!$row->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
return true;
}
function delete($id = array())
{
$result = false;
if (count( $cid ))
{
JArrayHelper::toInteger($cid);
$cids = implode( ',', $cid );
$query = 'DELETE FROM #__findme_style_link'
. ' WHERE id IN ( '.$cids.' )';
$this->_db->setQuery( $query );
if(!$this->_db->query()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return true;
}
function _loadData()
{
// Lets load the content if it doesn't already exist
if (empty($this->_data))
{
$query = 'SELECT * '
. ' FROM #__findme_style_link AS a WHERE a.id = '.(int) $this->_id;
echo 'query '.$query;
$this->_db->setQuery($query);
$this->_data = $this->_db->loadObject();
return (boolean) $this->_data;
}
return true;
}
function _initData()
{
// Lets load the content if it doesn't already exist
if (empty($this->_data))
{
$stylelink = new stdClass();
$stylelink->id = 0;
$stylelink->cat_id = null;
$stylelink->language = null;
$stylelink->name = null;
$stylelink->url_link = null;
$stylelink->url_img_small = null;
$stylelink->url_img_big = null;
$stylelink->active = null;
$stylelink->click_count = 0;
$this->_data = $stylelink;
return (boolean) $this->_data;
}
return true;
}
}
?>