อัพเดทการเขียน Component
สร้างตัวแปรภาษา
โค้ด: เลือกทั้งหมด
COM_TEST="Component Test"
COM_TEST_XML_DESCRIPTION="This component for test"
COM_TEST_CONTROL_PARNEL="Control Parnel"
COM_TEST_TEST="Test"
COM_TEST_HOME="Home"
COM_TEST_ABOUT="About"
โค้ด: เลือกทั้งหมด
COM_TEST="Component Test"
COM_TEST_XML_DESCRIPTION="คอมโพเน้นท์สำหรับการทดสอบ"
COM_TEST_CONTROL_PARNEL="Control Parnel"
COM_TEST_TEST="ทดสอบ"
COM_TEST_HOME="หน้าแรก"
COM_TEST_ABOUT="เกี่ยวกับเรา"
สร้างส่วน view
- Screenshot 2022-01-27 183425.png (27.44 KiB) Viewed 998 times
- Screenshot 2022-01-27 183439.png (27.39 KiB) Viewed 998 times
- Screenshot 2022-01-27 183458.png (27.83 KiB) Viewed 998 times
ส่วนโมเดล
สร้างส่วนรับค่า บันทึกข้อมูล และสร้างค้นหาข้อมูล
โค้ด: เลือกทั้งหมด
<?php
/**
* @package com_test
* @author mindphp developper
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
class TestModelTests extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'name', 'a.name',
'email', 'a.email',
'address', 'a.address',
'sendEmail', 'a.sendEmail',
'registerDate', 'a.registerDate',
'lastvisitDate', 'a.lastvisitDate',
'activation', 'a.activation',
'active',
'group_id',
'range',
'lastvisitrange',
'state',
);
}
parent::__construct($config);
}
protected function populateState($ordering = 'a.name', $direction = 'asc')
{
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
parent::populateState($ordering,$direction);
}
protected function getListQuery()
{
$db=$this->getDbo();
$query=$db->getListQuery(true);
$query->select('*')->from('#__tests AS a');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
// Escape the search token.
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
// Compile the different search clauses.
$searches = array();
$searches[] = 'a.name LIKE ' . $search;
$searches[] = 'a.email LIKE ' . $search;
$searches[] = 'a.address LIKE ' . $search;
// Add the clauses to the query.
$query->where('(' . implode(' OR ', $searches) . ')');
}
}
}
}
ตารางข้อมูล
โค้ด: เลือกทั้งหมด
-- phpMyAdmin SQL Dump
-- version 5.1.1
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Jan 27, 2022 at 11:42 AM
-- Server version: 5.7.33
-- PHP Version: 7.4.19
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `tool-mt49`
--
-- --------------------------------------------------------
--
-- Table structure for table `g5yd7_tests`
--
CREATE TABLE `g5yd7_tests` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`address` varchar(255) NOT NULL,
`created_by` int(11) NOT NULL,
`created_time` datetime NOT NULL,
`modefied_by` int(11) NOT NULL,
`modefied_time` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `g5yd7_tests`
--
ALTER TABLE `g5yd7_tests`
ADD PRIMARY KEY (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `g5yd7_tests`
--
ALTER TABLE `g5yd7_tests`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;