Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: вызов функций

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Без описания
andreydh
Отправлено: 17 Мая, 2013 - 18:15:41
Post Id


Новичок


Покинул форум
Сообщений всего: 1
Дата рег-ции: Май 2013  


Помог: 0 раз(а)




Подскажите, пожалуйста: хочу чтобы функции вызывались одна за одной при нажатии на соответствующую кнопку. Получильсь реализовать только если одна кнопка вызывает все функции

PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. class Clas {
  3.                
  4.     public function func1() {
  5.                 print "1";
  6.         }
  7.        
  8.         public function func2() {
  9.                 print "2";
  10.         }
  11.  
  12.         public function func3() {
  13.                 print "3";
  14.         }      
  15. }
  16. ?>
  17.  
  18. <form method="post">
  19. <input type="submit" name="start" value="start">
  20. <input type="submit" name="one" value="one">
  21. <input type="submit" name="two" value="two">
  22. <input type="submit" name="three" value="three">
  23. </form>
  24.  
  25. <?PHP
  26. if (isset ($_POST["start"])) {
  27.         $test = new Clas();
  28.         //$test->func1();
  29.         //$test->func2();
  30.         //$test->func3();
  31. }
  32.  
  33. if (isset ($_POST["one"])) {
  34.         $test->func1();
  35. }
  36.  
  37. if (isset ($_POST["two"])) {
  38.         $test->func2();
  39. }
  40.  
  41. if (isset ($_POST["three"])) {
  42.         $test->func3();
  43. }
  44. ?>
 
 Top
esterio
Отправлено: 17 Мая, 2013 - 18:23:38
Post Id



Активный участник


Покинул форум
Сообщений всего: 5025
Дата рег-ции: Нояб. 2012  
Откуда: Украина, Львов


Помог: 127 раз(а)




если нажата кнопка, например two - то не будет нажата ни кнопка one ни кнопкаthree. Такой механизм input[type=submit]. И старайтесь точнее виражать мысль
 
 Top
DelphinPRO
Отправлено: 17 Мая, 2013 - 18:29:49
Post Id



Активный участник


Покинул форум
Сообщений всего: 7187
Дата рег-ции: Февр. 2012  


Помог: 353 раз(а)




PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. class Clas {
  3.         public function func1() {
  4.                 return 1;
  5.         }
  6.  
  7.     public function func2() {
  8.                 return 2;
  9.         }
  10.  
  11.     public function func3() {
  12.                 return 3;
  13.         }
  14. }
  15.  
  16.  
  17. $result = '';
  18.  
  19. if (isset($_POST['start']) {
  20.         if (!isset($_SESSION['step'])) {
  21.                 $_SESSION['step'] = 1;
  22.         } else {
  23.                 $_SESSION['step']++;
  24.         }
  25.  
  26.         if ($_SESSION['step']>3) {
  27.                 $_SESSION['step'] = 1;
  28.         }
  29.  
  30.         $test = new Clas();
  31.         switch ($_SESSION['step']) {
  32.                 case 1:
  33.                         $result = $test->func1();
  34.                         break;
  35.                 case 2:
  36.                         $result = $test->func2();
  37.                         break;
  38.                 case 3:
  39.                         $result = $test->func3();
  40.                         break;
  41.                 default:
  42.                         $result = 'Error!';
  43.         }
  44. }
  45.  
  46. ?>
  47. <form method="post">
  48.         <input type="submit" name="start" value="start">
  49. </form>
  50. <?PHP echo $result; ?>

(Отредактировано автором: 17 Мая, 2013 - 18:31:18)



-----
Чем больше узнаю, тем больше я не знаю.
 
 Top
djuice
Отправлено: 18 Мая, 2013 - 08:47:11
Post Id



Новичок


Покинул форум
Сообщений всего: 8
Дата рег-ции: Апр. 2010  


Помог: 0 раз(а)




Помогите с сайтом.Обучаюсь по курсу OOP PHP mvc,но когда нужно выводить шаблон сайта на экран,то он не выводится.Хотя должна отработать public function get_page(){
echo $this->page;,а на экране ничего чистый экран.Что это может быть?

Вот код базового контрооллера
PHP:
скопировать код в буфер обмена
  1. <?PHP
  2. abstract class Base_Controller {
  3.         //свойства
  4.         protected $request_url;
  5.        
  6.         protected $controller;
  7.        
  8.         protected $params;
  9.        
  10.         protected $styles,$styles_admin;
  11.        
  12.         protected $scripts,$scripts_admin;
  13.        
  14.         protected $error;
  15.        
  16.         protected $page;
  17.        
  18.         //Методы
  19.         public function route(){
  20.                
  21.                 if(class_exists($this->controller)){
  22.                        
  23.                         $ref = new ReflectionClass($this->controller);
  24.                        
  25.                         if($ref->hasMethod('request')){
  26.                                
  27.                                 if($ref->isInstantiable()){
  28.                                         $class = $ref->newInstance();
  29.                                         $method = $ref->getMethod('request');
  30.                                         $method->invoke($class,$this->get_params());
  31.                                        
  32.                                 }
  33.                         }
  34.                 }
  35.                 else{
  36.                         throw new ContrException('Такой страницы не существует');
  37.                 }
  38.         }
  39.         public function init(){
  40.                
  41.                 global $conf;
  42.                
  43.                 if(isset($conf['styles'])){
  44.                         foreach($conf['styles'] as $style){
  45.                                 $this->styles[] = trim($style,'/');
  46.                         }
  47.                 }
  48.                 if(isset($conf['styles_amin'])){
  49.                         foreach($conf['styles_admin'] as $style_admin){
  50.                                 $this->styles_admin[] = trim($style_admin,'/');
  51.                         }
  52.                 }
  53.                 if(isset($conf['scripts'])){
  54.                         foreach($conf['scripts'] as $script){
  55.                                 $this->scripts[] = trim($script,'/');
  56.                         }
  57.                 }
  58.                 if(isset($conf['scripts_amin'])){
  59.                         foreach($conf['scripts_admin'] as $script_admin){
  60.                                 $this->scripts_admin[] = trim($script_admin,'/');
  61.                         }
  62.                 }
  63.         }
  64.         protected function get_controller(){
  65.                 return $this->controller;
  66.         }
  67.         protected function get_params(){
  68.                 return $this->params;
  69.         }
  70.         protected function input(){
  71.                
  72.         }
  73.         protected function output(){
  74.                
  75.         }
  76.         public function request($param = array()){
  77.                 $this->init();
  78.                 $this->input($param);
  79.                 $this->output();
  80.                
  81.                 if(!empty($this->error)){
  82.                         $this->write_error($this->error);      
  83.                 }
  84.                 $this->get_page();
  85.         }
  86.         public function get_page(){
  87.                 echo $this->page;      
  88.         }
  89.         protected function render($path,$param = array()){
  90.                
  91.                 extract($param);
  92.                
  93.                 ob_start();
  94.                
  95.                 if(!include($path.'.php')){
  96.                         throw new ContrException('Данного шаблона не существует.');
  97.                 }
  98.                 return ob_get_clean();
  99.         }
  100.         public function clear_str($var){
  101.                 if(is_array($var)){
  102.                         $row = array();
  103.                         foreach($var as $key => $item){
  104.                                 $row[$key] = trim(strip_tags($item));
  105.                         }
  106.                         return $row;
  107.                 }
  108.                 return trim(strip_tags($var));
  109.         }
  110.         public function clear_int($var){
  111.                 return (int)$var;
  112.         }
  113.         public function is_post(){
  114.                 if($_SERVER['REQUEST_METHOD'] == 'POST'){
  115.                 return TRUE;   
  116.                 }
  117.                 return FALSE;
  118.         }
  119.         public function check_auth(){
  120.                
  121.         }
  122.         public function write_error($err){
  123.                 $time = date("d-m-Y G:i:s");
  124.                
  125.                 $str = "Fault: ".$time." - ".$err."\n\r";
  126.                 file_put_contents("log.txt",$str,FILE_APPEND);
  127.         }
  128.         public function img_resize($dest){
  129.                
  130.         }
  131. }
  132. ?>
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Объектно-ориентированное программирование »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB