 |
[PHP]
รบกวนช่วยแก้ให้ทีครับ php และ mysql ตัวนี้ครับ $this |
|
 |
|
|
 |
 |
|
คือผมทำ php ไม่เป็นน่ะครับ แก้มาทั้งวันแล้ว มันก็เลยไม่ไปไหนซักที
อันนี้โค๊ดนะครับ
Code (PHP)
01. <?php
02. @session_start();
03. include_once ( "../admin/config.php" );
04. @mysql_connect( "localhost" , DB_USERNAME, DB_PASSWORD);
05. @mysql_select_db(DB_DATABASE) or die (mysql_error());
06. @mysql_query( "set NAMES utf8" );
07.
08. if ( $this ->customer->isLogged();){
09. echo "" . $this ->customer->getFirstName(). "" ;
10. } else {
11. echo "Guess" ; }
12. ?>
ส่วนติดต่อฐานข้อมูลใช้ได้แต่ติดปัญหาด้านล่างครับ ผมก็อปด้านล่างมาจาก theme ของ opencart น่ะครับ แต่อันนี้ผมมาสร้าง file php ขึ้นมาใหม่เองและไว้ที่ root คิดว่าน่าจะมีปัญหาเพราะตัวนี้ครับ $this มันต้องอยู่ใน class เท่าที่ผมหาดูแต่ผมเขียน class เพิ่มไม่เป็นน่ะครับ ลองแล้ว error ตลอด ถ้าจะเปลี่ยนจาก $this เป็นอย่างอื่นจะทำได้หรือเปล่าครับ
Code (PHP)
1. if ( $this ->customer->isLogged();){
2. echo "" . $this ->customer->getFirstName(). "" ;
3. } else {
4. echo "Guess" ; }
ใช้แสดงว่าถ้า login จะขึ้นชื่อผู้ใช้คนนั้นแต่ถ้าไม่ login จะขึ้นว่า Guess
Tag : PHP, MySQL, HTML/CSS
|
|
 |
 |
 |
 |
Date :
2012-03-29 01:27:30 |
By :
PM |
View :
1517 |
Reply :
15 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$this อยู่ในไฟล์ไหนให้ include ไฟลืนั้นมาแล้ว new class ที่มันอยู่ครับ งงมะ
|
 |
 |
 |
 |
Date :
2012-03-29 02:55:34 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
include ไฟล์ อันนี้เข้าใจครับ class ของมันก็พอรู้เรื่องแต่ผมไม่รู้โครงสร้าง class มันเป็นยังไง กลัวเอามาไม่หมดหรือเกิน รบกวนช่วย เขียนตัวอย่างโครงของมันให้ทีครับ ขอบคุณมากครับ 
|
 |
 |
 |
 |
Date :
2012-03-29 03:32:47 |
By :
PM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำจริงแล้วมึนมากครับ มันถามหา class Controller อีก หรือผมทำผิดเนี่ย นี่คือโค๊ดที่มี $this นะครับ ชื่อไฟล์ว่า board.php
Code (PHP)
01. <?php
02. class Controllerwebboardboard extends Controller {
03. public function index() {
04. $this ->document->breadcrumbs = array ();
05.
06. if ( $this ->customer->isLogged();){
07. echo "" . $this ->customer->getFirstName(). "" ;
08. } else {
09. echo "Guess" ; }
10.
11. }
12.
13. }
14.
15. ?>
ส่วนไฟล์ที่ผมทำใหม่อันนี้ครับ
Code (PHP)
01. <?php
02. @session_start();
03. include_once ( "../admin/config.php" );
04. include_once ( "../Controller/webboard/board.php" );
05. @mysql_connect( "localhost" , DB_USERNAME, DB_PASSWORD);
06. @mysql_select_db(DB_DATABASE) or die (mysql_error());
07. @mysql_query( "set NAMES utf8" );
08.
09. class Controllerwebboardboard extends Controller {
10. public function index() {
11.
12. if ( $this ->customer->isLogged();){
13. echo "" . $this ->customer->getFirstName(). "" ;
14. } else {
15. echo "Guess" ; }
16.
17. }
18.
19. }
20.
21.
22. ?>
|
 |
 |
 |
 |
Date :
2012-03-29 04:25:18 |
By :
PM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อีกไฟล์ที่มี $this เหมือนกันครับ รบกวนด้วยครับ
อันนี้ไฟล์ชื่อ header.php ไฟล์อยู่ที่ /catalog/controller/common น่าจะเกี่ยวข้องด้วย ในโค๊ดตรงสีแดงครับ
Code
<?php
class ControllerCommonHeader extends Controller {
protected function index() {
$this->data['title'] = $this->document->getTitle();
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$this->data['base'] = $this->config->get('config_ssl');
} else {
$this->data['base'] = $this->config->get('config_url');
}
$this->data['description'] = $this->document->getDescription();
$this->data['keywords'] = $this->document->getKeywords();
$this->data['links'] = $this->document->getLinks();
$this->data['styles'] = $this->document->getStyles();
$this->data['scripts'] = $this->document->getScripts();
$this->data['lang'] = $this->language->get('code');
$this->data['direction'] = $this->language->get('direction');
$this->data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
$this->language->load('common/header');
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$server = HTTPS_IMAGE;
} else {
$server = HTTP_IMAGE;
}
if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) {
$this->data['icon'] = $server . $this->config->get('config_icon');
} else {
$this->data['icon'] = '';
}
$this->data['name'] = $this->config->get('config_name');
if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
$this->data['logo'] = $server . $this->config->get('config_logo');
} else {
$this->data['logo'] = '';
}
$this->data['text_home'] = $this->language->get('text_home');
$this->data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));
$this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
$this->data['text_search'] = $this->language->get('text_search');
$this->data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
$this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
$this->data['text_account'] = $this->language->get('text_account');
$this->data['text_checkout'] = $this->language->get('text_checkout');
$this->data['text_affiliate'] = $this->language->get('text_affiliate');
$this->data['home'] = $this->url->link('common/home');
$this->data['wishlist'] = $this->url->link('account/wishlist');
$this->data['logged'] = $this->customer->isLogged();
$this->data['account'] = $this->url->link('account/account', '', 'SSL');
$this->data['shopping_cart'] = $this->url->link('checkout/cart');
$this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
$this->data['search'] = $this->url->link('product/search');
$this->data['text_sitemap'] = $this->language->get('text_sitemap');
$this->data['affiliate'] = $this->url->link('affiliate/account', '', 'SSL');
$this->data['sitemap'] = $this->url->link('information/sitemap');
$this->data['text_contact'] = $this->language->get('text_contact');
$this->data['contact'] = $this->url->link('information/contact');
$this->data['text_special'] = $this->language->get('text_special');
$this->data['special'] = $this->url->link('product/special');
$this->data['text_newsletter'] = $this->language->get('text_newsletter');
$this->data['newsletter'] = $this->url->link('account/newsletter', '', 'SSL');
if (isset($this->request->get['filter_name'])) {
$this->data['filter_name'] = $this->request->get['filter_name'];
} else {
$this->data['filter_name'] = '';
}
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$product_total = $this->model_catalog_product->getTotalProducts($data);
$children_data[] = array(
'name' => $child['name'] . ' (' . $product_total . ')',
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$this->data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$this->children = array(
'module/language',
'module/currency',
'module/cart'
);
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/header.tpl';
} else {
$this->template = 'default/template/common/header.tpl';
}
$this->render();
}
}
?>
อันนี้อีกไฟล์นึงครับ header.tpl ไฟล์อยู่ที่ /catalog/view/theme/miwa_pink/template/common มันก็น่าจะเป็นพวก php มั้งครับ แต่ opencart เขาให้ใช้นามสกุล tpl แทน สีแดงคือส่วนที่ผมต้องการ แต่ผมเอาแค่ $logged เพราะจะใช้เช็คว่าถ้าสมาชิกล็อกอินให้ทำอย่างนึงถ้าไม่ก็ทำอีกอย่าง
Code
<?php if (isset($_SERVER['HTTP_USER_AGENT']) && !strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6')) echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $direction; ?>" lang="<?php echo $lang; ?>" xml:lang="<?php echo $lang; ?>">
<head>
<title><?php echo $title; ?></title>
<base href="<?php echo $base; ?>" />
<?php if ($description) { ?>
<meta name="description" content="<?php echo $description; ?>" />
<?php } ?>
<?php if ($keywords) { ?>
<meta name="keywords" content="<?php echo $keywords; ?>" />
<?php } ?>
<?php if ($icon) { ?>
<link href="<?php echo $icon; ?>" rel="icon" />
<?php } ?>
<?php foreach ($links as $link) { ?>
<link href="<?php echo $link['href']; ?>" rel="<?php echo $link['rel']; ?>" />
<?php } ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/miwa_pink/stylesheet/stylesheet.css" />
<?php foreach ($styles as $style) { ?>
<link rel="<?php echo $style['rel']; ?>" type="text/css" href="<?php echo $style['href']; ?>" media="<?php echo $style['media']; ?>" />
<?php } ?>
<script type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/ui/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/ui/themes/ui-lightness/jquery-ui-1.8.16.custom.css" />
<script type="text/javascript" src="catalog/view/javascript/jquery/ui/external/jquery.cookie.js"></script>
<script type="text/javascript" src="catalog/view/javascript/jquery/colorbox/jquery.colorbox.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/colorbox/colorbox.css" media="screen" />
<script type="text/javascript" src="catalog/view/javascript/jquery/tabs.js"></script>
<script type="text/javascript" src="catalog/view/javascript/common.js"></script>
<?php foreach ($scripts as $script) { ?>
<script type="text/javascript" src="<?php echo $script; ?>"></script>
<?php } ?>
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/ie7.css" />
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/default/stylesheet/ie6.css" />
<script type="text/javascript" src="catalog/view/javascript/DD_belatedPNG_0.0.8a-min.js"></script>
<script type="text/javascript">
DD_belatedPNG.fix('#logo img');
</script>
<![endif]-->
<?php echo $google_analytics; ?>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/th_TH/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<div id="container">
<div id="header">
<?php if ($logo) { ?>
<div id="logo"><a href="<?php echo $home; ?>"><img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" /></a></div>
<?php } ?>
<?php echo $language; ?>
<?php echo $currency; ?>
<?php echo $cart; ?>
<div id="search">
<div class="button-search"></div>
<?php if ($filter_name) { ?>
<input type="text" name="filter_name" value="<?php echo $filter_name; ?>" />
<?php } else { ?>
<input type="text" name="filter_name" value="<?php echo $text_search; ?>" onclick="this.value = '';" onkeydown="this.style.color = '#444444';" />
<?php } ?>
</div>
<div id="welcome">
<?php if (!$logged) { ?>
<?php echo $text_welcome; ?>
<?php } else { ?>
<?php echo $text_logged; ?>
<?php } ?>
</div>
<div class="links"><a href="<?php echo $home; ?>"><?php echo $text_home; ?></a><a href="<?php echo $wishlist; ?>" id="wishlist-total"><?php echo $text_wishlist; ?></a><a href="<?php echo $account; ?>"><?php echo $text_account; ?></a><a href="<?php echo $shopping_cart; ?>"><?php echo $text_shopping_cart; ?></a><a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a></div>
</div>
<?php if ($categories) { ?>
<div id="menu">
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
<?php if ($category['children']) { ?>
<div>
<?php for ($i = 0; $i < count($category['children']);) { ?>
<ul>
<?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($category['children'][$i])) { ?>
<li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
<div id="notification"></div>
|
 |
 |
 |
 |
Date :
2012-03-29 04:59:46 |
By :
PM |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
01. <?php
02. @session_start();
03. include_once ( "../admin/config.php" );
04. include_once ( "../Controller/webboard/board.php" );
05. @mysql_connect( "localhost" , DB_USERNAME, DB_PASSWORD);
06. @mysql_select_db(DB_DATABASE) or die (mysql_error());
07. @mysql_query( "set NAMES utf8" );
08.
09. $board = new Controllerwebboardboard;
10.
11. if ( $board ->customer->isLogged();){
12. echo "" . $board ->customer->getFirstName(). "" ;
13. } else {
14. echo "Guess" ; }
15. }
16. ?>
ลองดูว่าแบบมั่วๆ นี่ได้ไหม ขี้เกียจไล่โค๊ดยาว
|
 |
 |
 |
 |
Date :
2012-03-29 05:38:34 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ้ นอนดึกจังครับ หรือตื่นเช้าเนี่ย
ไม่ได้น่ะครับขึ้นว่า
Fatal error: Class 'Controller' not found in /home/a4818hos/public_html/catalog/controller/webboard/board.php on line 2
|
 |
 |
 |
 |
Date :
2012-03-29 10:32:15 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้อง include ไฟล์ที่มี class ที่เกี่ยวข้องมาให้หมดอะครับ
|
 |
 |
 |
 |
Date :
2012-03-29 10:49:29 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ เดี๋ยวจะลองดูครับ ดูเหนื่อยดีแฮะ 
|
 |
 |
 |
 |
Date :
2012-03-29 11:03:43 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่มีวิธีเช็คการ login โดยตรงจาก ฐานข้อมูลหรือวิธีอื่นเหรอครับ = =
|
 |
 |
 |
 |
Date :
2012-03-29 11:09:50 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณใช้ บอร์ดยี่ห้อไหนหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-03-29 11:11:12 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บอร์ด ใช้เขียนเอาจากที่นี่แหละครับ ส่วน ร้านใช้ opencart
|
 |
 |
 |
 |
Date :
2012-03-29 11:17:22 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สู้อีกครั้ง ไม่ยอมๆต้องทำให้ได้
include_once($root.'/admin/config.php'); ต้องการให้มันไปหน้า root /public_html/ ต้องใช้คำสั่งอะไรครับ ผมลองย้าย board ไปไว้ในตัว opencart แต่มันเรียก admin/config.php ไม่ได้
|
 |
 |
 |
 |
Date :
2012-03-29 11:51:02 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำใหม่น่าจะได้แต่ก็ติดตรง หน้าสำหรับแสดงข้อมูลบอร์ดปกติคือ webboard/view.php?QuestionID=หมายเลขกระทู้ แต่พอผมยัดบอร์ดเข้าไปใน opencart ลิ้งค์สำหรับเข้าบอร์ดจะเปลี่ยนเป็น index.php?route=webboard/board แล้วลิ้งค์กระทู้ก็กลายเป็น index.php?route=webboard/view/ ซึ่งมันใช้ ?QuestionID= ไม่ได้ ผมจะแก้ยังไงดีครับ
|
 |
 |
 |
 |
Date :
2012-03-29 12:18:02 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมทำมั่วๆคิดว่ามันน่าจะได้แล้ว ขอบคุณมากนะครับ ที่แก้ให้ผม
|
 |
 |
 |
 |
Date :
2012-03-29 13:57:07 |
By :
pm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|